diff --git a/.gitignore b/.gitignore index 45a3bec5d..5cd074a6a 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ /classes /bin/ /run/ +/runs/ *.classpath *.project diff --git a/build.gradle b/build.gradle index 25b10ac27..a754aaa41 100644 --- a/build.gradle +++ b/build.gradle @@ -1,9 +1,9 @@ plugins { + id 'java-library' id 'eclipse' id 'idea' id 'maven-publish' - id 'net.minecraftforge.gradle' version '[6.0,6.2)' - id 'org.parchmentmc.librarian.forgegradle' version '1.+' + id 'net.neoforged.gradle.userdev' version '7.0.96' } version = "$mod_version" @@ -16,44 +16,49 @@ if (System.getenv('BUILD_NUMBER') != null) { version += "." + System.getenv('BUILD_NUMBER') } +// Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17. java.toolchain.languageVersion = JavaLanguageVersion.of(17) -minecraft { - mappings channel: 'parchment', version: "${parchment_version}-${game_version}" - // makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable. +if (rootProject.file('src/main/resources/META-INF/accesstransformer.cfg').exists()) { + minecraft.accessTransformers.file rootProject.file('src/main/resources/META-INF/accesstransformer.cfg') +} +//minecraft.accessTransformers.entry public net.minecraft.client.Minecraft textureManager # textureManager - accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') +runs { + // applies to all the run configs below + configureEach { net.neoforged.gradle.dsl.common.runs.run.Run run -> + // Recommended logging data for a userdev environment + systemProperty 'forge.logging.markers', 'REGISTRIES' - runs { - client { - workingDirectory project.file('run') - - mods { - actuallyadditions { - source sourceSets.main - } - } + // Recommended logging level for the console + systemProperty 'forge.logging.console.level', 'debug' + + //Limit ram usage for the dev environment to 4GB + jvmArgument '-Xmx4G' + + if (run.project.javaToolchains.launcherFor(java.toolchain).map { it.metadata.vendor }.getOrElse("").contains("JetBrains")) { + run.jvmArgument("-XX:+AllowEnhancedClassRedefinition") } - server { - workingDirectory project.file('run') - mods { - actuallyadditions { - source sourceSets.main - } - } - } + modSource project.sourceSets.main + } - data { - workingDirectory project.file('run') - args '--mod', 'actuallyadditions', '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/') + client { + // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. + systemProperty 'neoforge.enabledGameTestNamespaces', "actuallyadditions" + } - mods { - actuallyadditions { - source sourceSets.main - } - } - } + server { + systemProperty 'neoforge.enabledGameTestNamespaces', "actuallyadditions" + programArgument '--nogui' + } + + data { + // example of overriding the workingDirectory set in configureEach above, uncomment if you want to use it + // workingDirectory 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', "actuallyadditions", '--all', '--output', file('src/generated/resources/').getAbsolutePath(), '--existing', file('src/main/resources/').getAbsolutePath() } } @@ -64,20 +69,23 @@ repositories { url = "https://maven.blamejared.com" } maven { - url = "https://www.cursemaven.com" + url "https://cursemaven.com" + content { + includeGroup "curse.maven" + } } } dependencies { - minecraft "net.minecraftforge:forge:${game_version}-${forge_version}" + implementation "net.neoforged:neoforge:${neo_version}" - compileOnly fg.deobf("mezz.jei:jei-${game_version}-common-api:${jei_version}") - compileOnly fg.deobf("mezz.jei:jei-${game_version}-forge-api:${jei_version}") + compileOnly "mezz.jei:jei-${game_version}-common-api:${jei_version}" + compileOnly "mezz.jei:jei-${game_version}-neoforge-api:${jei_version}" - runtimeOnly fg.deobf("mezz.jei:jei-${game_version}-forge:${jei_version}") + runtimeOnly "mezz.jei:jei-${game_version}-neoforge:${jei_version}" - runtimeOnly fg.deobf("curse.maven:the-one-probe-245211:4629624") - runtimeOnly fg.deobf("curse.maven:mekanism-268560:5125665") + runtimeOnly "curse.maven:the-one-probe-245211:5084077" + runtimeOnly "curse.maven:mekanism-268560:5155329" } // not sure if this is still needed @@ -107,12 +115,6 @@ jar { from sourceSets.main.output } -task deobfJar(type: Jar) { - from sourceSets.main.output - from sourceSets.main.java - archiveClassifier.set('dev') -} - task apiJar(type: Jar) { from sourceSets.main.output from sourceSets.main.java @@ -135,7 +137,7 @@ task sourcesJar(type: Jar) { } artifacts { - archives deobfJar, sourcesJar, apiJar, javadocJar + archives sourcesJar, apiJar, javadocJar } publishing { @@ -148,7 +150,6 @@ publishing { from components.java - artifact deobfJar artifact sourcesJar artifact apiJar artifact javadocJar diff --git a/gradle.properties b/gradle.properties index b8c4072a7..484609bcf 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,11 +6,12 @@ org.gradle.daemon=false mod_version=1.1.52 # Forge -game_version=1.20.1 -forge_version=47.1.3 +game_version=1.20.4 +neo_version=20.4.190 # Parchment (Mappings) -parchment_version=2023.09.03 +neogradle.subsystems.parchment.minecraftVersion=1.20.4 +neogradle.subsystems.parchment.mappingsVersion=2024.02.25 # Other mods -jei_version=15.3.0.4 +jei_version=17.3.0.49 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 943f0cbfa..d64cd4917 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 37aef8d3f..a80b22ce5 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 65dcd68d6..1aa94a426 100755 --- a/gradlew +++ b/gradlew @@ -83,10 +83,8 @@ done # This is normally unused # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -133,10 +131,13 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. @@ -144,7 +145,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac @@ -152,7 +153,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then '' | soft) :;; #( *) # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -197,11 +198,15 @@ if "$cygwin" || "$msys" ; then done fi -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ diff --git a/gradlew.bat b/gradlew.bat index 6689b85be..7101f8e46 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/logs/debug.log b/logs/debug.log deleted file mode 100644 index e69de29bb..000000000 diff --git a/logs/latest.log b/logs/latest.log deleted file mode 100644 index e69de29bb..000000000 diff --git a/settings.gradle b/settings.gradle index b7fe2dc86..b03169b5f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -2,13 +2,12 @@ pluginManagement { repositories { gradlePluginPortal() maven { - name = 'MinecraftForge' - url = 'https://maven.minecraftforge.net/' + name = 'Official NeoForge Maven' + url = 'https://maven.neoforged.net/releases' } - maven { url = 'https://maven.parchmentmc.org' } } } plugins { - id 'org.gradle.toolchains.foojay-resolver-convention' version '0.5.0' -} \ No newline at end of file + id 'org.gradle.toolchains.foojay-resolver-convention' version '0.8.0' +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java b/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java index 692d4d5ba..fa006af74 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java +++ b/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java @@ -20,6 +20,7 @@ import de.ellpeck.actuallyadditions.api.lens.Lens; import de.ellpeck.actuallyadditions.api.lens.LensConversion; import de.ellpeck.actuallyadditions.api.recipe.CoffeeIngredient; import de.ellpeck.actuallyadditions.api.recipe.WeightedOre; +import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.crafting.ColorChangeRecipe; import de.ellpeck.actuallyadditions.mod.crafting.CrushingRecipe; import de.ellpeck.actuallyadditions.mod.crafting.EmpowererRecipe; @@ -35,9 +36,12 @@ import de.ellpeck.actuallyadditions.mod.items.lens.LensDetonation; import de.ellpeck.actuallyadditions.mod.items.lens.LensDisenchanting; import de.ellpeck.actuallyadditions.mod.items.lens.LensKiller; import de.ellpeck.actuallyadditions.mod.items.lens.LensMining; +import net.minecraft.core.NonNullList; +import net.minecraft.core.registries.BuiltInRegistries; 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 java.util.ArrayList; import java.util.List; @@ -48,15 +52,15 @@ public final class ActuallyAdditionsAPI { public static final String API_ID = MOD_ID + "api"; public static final String API_VERSION = "34"; - public static final List CRUSHER_RECIPES = new ArrayList<>(); - public static final List EMPOWERER_RECIPES = new ArrayList<>(); - public static final List COLOR_CHANGE_RECIPES = new ArrayList<>(); - public static final List SOLID_FUEL_RECIPES = new ArrayList<>(); - public static final List LIQUID_FUEL_RECIPES = new ArrayList<>(); - public static final List PRESSING_RECIPES = new ArrayList<>(); - public static final List FERMENTING_RECIPES = new ArrayList<>(); - public static final List CONVERSION_LASER_RECIPES = new ArrayList<>(); - public static final List MINING_LENS_RECIPES = new ArrayList<>(); + public static final List> CRUSHER_RECIPES = new ArrayList<>(); + public static final List> EMPOWERER_RECIPES = new ArrayList<>(); + public static final List> COLOR_CHANGE_RECIPES = new ArrayList<>(); + public static final List> SOLID_FUEL_RECIPES = new ArrayList<>(); + public static final List> LIQUID_FUEL_RECIPES = new ArrayList<>(); + public static final List> PRESSING_RECIPES = new ArrayList<>(); + public static final List> FERMENTING_RECIPES = new ArrayList<>(); + public static final List> CONVERSION_LASER_RECIPES = new ArrayList<>(); + public static final List> MINING_LENS_RECIPES = new ArrayList<>(); /** * Farmer behaviors are sorted when first accessed, this will not be done until after loading, but do not add behaviors at runtime. @@ -142,28 +146,30 @@ public final class ActuallyAdditionsAPI { * Adds a Recipe to the Crusher Recipe Registry * * @param input The input as an ItemStack - * @param outputOne The first output as an ItemStack - * @param outputTwo The second output as an ItemStack (can be ItemStack.EMPTY if there should be none) - * @param outputTwoChance The chance of the second output (0 won't occur at all, 100 will all the time) + * @param outputOne The first stack as an ItemStack + * @param outputTwo The second stack as an ItemStack (can be ItemStack.EMPTY if there should be none) + * @param outputTwoChance The chance of the second stack (0 won't occur at all, 100 will all the time) */ public static void addCrusherRecipe(ItemStack input, ItemStack outputOne, ItemStack outputTwo, int outputTwoChance) { - CRUSHER_RECIPES.add(new CrushingRecipe(Ingredient.of(input), outputOne, 1.0f, outputTwo.isEmpty() + ResourceLocation id = new ResourceLocation(ActuallyAdditions.MODID, BuiltInRegistries.ITEM.getKey(input.getItem()).getPath() + "_crushing"); + CRUSHER_RECIPES.add(new RecipeHolder<>(id, new CrushingRecipe(Ingredient.of(input), outputOne, 1.0f, outputTwo.isEmpty() ? ItemStack.EMPTY - : outputTwo, outputTwoChance)); + : outputTwo, outputTwoChance))); } /** * Adds a Recipe to the Crusher Recipe Registry * * @param input The input as an Ingredient - * @param outputOne The first output as an ItemStack - * @param outputTwo The second output as an ItemStack (can be ItemStack.EMPTY if there should be none) - * @param outputTwoChance The chance of the second output (0 won't occur at all, 100 will all the time) + * @param outputOne The first stack as an ItemStack + * @param outputTwo The second stack as an ItemStack (can be ItemStack.EMPTY if there should be none) + * @param outputTwoChance The chance of the second stack (0 won't occur at all, 100 will all the time) */ public static void addCrusherRecipe(Ingredient input, ItemStack outputOne, ItemStack outputTwo, int outputTwoChance) { - CRUSHER_RECIPES.add(new CrushingRecipe(input, outputOne, 1.0f, outputTwo.isEmpty() - ? ItemStack.EMPTY - : outputTwo, outputTwoChance)); + ResourceLocation id = new ResourceLocation(ActuallyAdditions.MODID, BuiltInRegistries.ITEM.getKey(input.getItems()[0].getItem()).getPath() + "_crushing"); + CRUSHER_RECIPES.add(new RecipeHolder<>(id, new CrushingRecipe(input, outputOne, 1.0f, outputTwo.isEmpty() + ? ItemStack.EMPTY + : outputTwo, outputTwoChance))); } /** @@ -172,10 +178,10 @@ public final class ActuallyAdditionsAPI { * * @param inputs The inputs as an ItemStack List, stacksizes are ignored * @param outputOnes The first outputs as an ItemStack List, stacksizes are ignored - * @param outputOneAmounts The amount of the first output, will be equal for all entries in the list + * @param outputOneAmounts The amount of the first stack, will be equal for all entries in the list * @param outputTwos The second outputs as a List (can be null or empty if there should be none) - * @param outputTwoAmounts The amount of the second output, will be equal for all entries in the list - * @param outputTwoChance The chance of the second output (0 won't occur at all, 100 will all the time) + * @param outputTwoAmounts The amount of the second stack, will be equal for all entries in the list + * @param outputTwoChance The chance of the second stack (0 won't occur at all, 100 will all the time) */ public static boolean addCrusherRecipes(List inputs, List outputOnes, int outputOneAmounts, List outputTwos, int outputTwoAmounts, int outputTwoChance) { return methodHandler.addCrusherRecipes(inputs, outputOnes, outputOneAmounts, outputTwos, outputTwoAmounts, outputTwoChance); @@ -188,7 +194,8 @@ public final class ActuallyAdditionsAPI { } public static void addEmpowererRecipe(ResourceLocation id, Ingredient input, ItemStack output, Ingredient modifier1, Ingredient modifier2, Ingredient modifier3, Ingredient modifier4, int energyPerStand, int time, int particleColor) { - EMPOWERER_RECIPES.add(new EmpowererRecipe(id, output, input, modifier1, modifier2, modifier3, modifier4, energyPerStand, time, particleColor)); + EmpowererRecipe recipe = new EmpowererRecipe(output, input, NonNullList.of(modifier1, modifier2, modifier3, modifier4), energyPerStand, time, particleColor); + EMPOWERER_RECIPES.add(new RecipeHolder<>(id, recipe)); } /** @@ -196,19 +203,19 @@ public final class ActuallyAdditionsAPI { * StackSizes can only be 1 and greater ones will be ignored * * @param input The input as an ItemStack - * @param output The output as an ItemStack + * @param output The stack as an ItemStack * @param energyUse The amount of RF used per conversion * @param type The type of lens used for the conversion. To use the default type, use method below. * Note how this always has to be the same instance of the lens type that the item also has for it to work! */ @Deprecated public static void addReconstructorLensConversionRecipe(ItemStack input, ItemStack output, int energyUse, LensConversion type) { - //RECONSTRUCTOR_LENS_CONVERSION_RECIPES.add(new LensConversionRecipe(input, output, energyUse, type)); + //RECONSTRUCTOR_LENS_CONVERSION_RECIPES.add(new LensConversionRecipe(input, stack, energyUse, type)); } @Deprecated public static void addReconstructorLensConversionRecipe(ItemStack input, ItemStack output, int energyUse) { - //addReconstructorLensConversionRecipe(input, output, energyUse, lensDefaultConversion); + //addReconstructorLensConversionRecipe(input, stack, energyUse, lensDefaultConversion); } /** @@ -216,17 +223,17 @@ public final class ActuallyAdditionsAPI { * StackSizes can only be 1 and greater ones will be ignored * * @param input The input as an ItemStack - * @param output The output as an ItemStack + * @param output The stack as an ItemStack * @param energyUse The amount of RF used per conversion * @param type The type of lens used for the conversion. To use the default type, use method below. * Note how this always has to be the same instance of the lens type that the item also has for it to work! */ public static void addReconstructorLensConversionRecipe(Ingredient input, ItemStack output, int energyUse, LensConversion type) { - //RECONSTRUCTOR_LENS_CONVERSION_RECIPES.add(new LensConversionRecipe(input, output, energyUse, type)); + //RECONSTRUCTOR_LENS_CONVERSION_RECIPES.add(new LensConversionRecipe(input, stack, energyUse, type)); } public static void addReconstructorLensConversionRecipe(Ingredient input, ItemStack output, int energyUse) { - //addReconstructorLensConversionRecipe(input, output, energyUse, lensDefaultConversion); + //addReconstructorLensConversionRecipe(input, stack, energyUse, lensDefaultConversion); } /** * Adds an ingredient to the Coffee Machine ingredient list diff --git a/src/main/java/de/ellpeck/actuallyadditions/api/booklet/IBookletChapter.java b/src/main/java/de/ellpeck/actuallyadditions/api/booklet/IBookletChapter.java index bac2207da..8c8c3cdab 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/api/booklet/IBookletChapter.java +++ b/src/main/java/de/ellpeck/actuallyadditions/api/booklet/IBookletChapter.java @@ -11,8 +11,8 @@ package de.ellpeck.actuallyadditions.api.booklet; import net.minecraft.world.item.ItemStack; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; public interface IBookletChapter { diff --git a/src/main/java/de/ellpeck/actuallyadditions/api/booklet/IBookletEntry.java b/src/main/java/de/ellpeck/actuallyadditions/api/booklet/IBookletEntry.java index b91e0beac..aacfc8bbb 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/api/booklet/IBookletEntry.java +++ b/src/main/java/de/ellpeck/actuallyadditions/api/booklet/IBookletEntry.java @@ -10,8 +10,8 @@ package de.ellpeck.actuallyadditions.api.booklet; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import java.util.List; diff --git a/src/main/java/de/ellpeck/actuallyadditions/api/booklet/IBookletPage.java b/src/main/java/de/ellpeck/actuallyadditions/api/booklet/IBookletPage.java index ca84df9b8..5af30f3f8 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/api/booklet/IBookletPage.java +++ b/src/main/java/de/ellpeck/actuallyadditions/api/booklet/IBookletPage.java @@ -13,9 +13,9 @@ package de.ellpeck.actuallyadditions.api.booklet; import de.ellpeck.actuallyadditions.api.booklet.internal.GuiBookletBase; import net.minecraft.client.gui.components.Button; import net.minecraft.world.item.ItemStack; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.fluids.FluidStack; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; +import net.neoforged.neoforge.fluids.FluidStack; import java.util.List; diff --git a/src/main/java/de/ellpeck/actuallyadditions/data/ActuallyAdditionsData.java b/src/main/java/de/ellpeck/actuallyadditions/data/ActuallyAdditionsData.java index 9e871e407..f2674fdc5 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/data/ActuallyAdditionsData.java +++ b/src/main/java/de/ellpeck/actuallyadditions/data/ActuallyAdditionsData.java @@ -3,6 +3,7 @@ package de.ellpeck.actuallyadditions.data; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.config.conditions.BoolConfigCondition; import de.ellpeck.actuallyadditions.mod.misc.ActuallyDamageTypes; +import net.minecraft.core.Cloner; import net.minecraft.core.HolderLookup; import net.minecraft.core.RegistryAccess; import net.minecraft.core.RegistrySetBuilder; @@ -12,12 +13,12 @@ import net.minecraft.data.DataGenerator; import net.minecraft.data.PackOutput; import net.minecraft.data.registries.VanillaRegistries; import net.minecraft.world.damagesource.DamageType; -import net.minecraftforge.common.crafting.CraftingHelper; -import net.minecraftforge.common.data.DatapackBuiltinEntriesProvider; -import net.minecraftforge.common.data.ExistingFileHelper; -import net.minecraftforge.data.event.GatherDataEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod; +import net.neoforged.neoforge.common.crafting.CraftingHelper; +import net.neoforged.neoforge.common.data.DatapackBuiltinEntriesProvider; +import net.neoforged.neoforge.common.data.ExistingFileHelper; +import net.neoforged.neoforge.data.event.GatherDataEvent; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.Mod; import java.util.Set; import java.util.concurrent.CompletableFuture; @@ -27,10 +28,10 @@ public class ActuallyAdditionsData { @SubscribeEvent public static void runGenerator(GatherDataEvent event) { - CraftingHelper.register(BoolConfigCondition.Serializer.INSTANCE); DataGenerator generator = event.getGenerator(); PackOutput packOutput = generator.getPackOutput(); - CompletableFuture lookupProvider = CompletableFuture.supplyAsync(ActuallyAdditionsData::getProvider); + CompletableFuture patchedProvider = CompletableFuture.supplyAsync(ActuallyAdditionsData::getProvider); + CompletableFuture lookupProvider = CompletableFuture.supplyAsync(() -> ActuallyAdditionsData.getProvider().full()); ExistingFileHelper helper = event.getExistingFileHelper(); // generator.addProvider(new GeneratorLanguage(generator)); @@ -58,18 +59,20 @@ public class ActuallyAdditionsData { generator.addProvider(true, new SoundsGenerator(packOutput, helper)); generator.addProvider(event.includeServer(), new DatapackBuiltinEntriesProvider( - packOutput, lookupProvider, Set.of(ActuallyAdditions.MODID))); + packOutput, patchedProvider, Set.of(ActuallyAdditions.MODID))); } - private static HolderLookup.Provider getProvider() { + private static RegistrySetBuilder.PatchedRegistries getProvider() { final RegistrySetBuilder registryBuilder = new RegistrySetBuilder(); registryBuilder.add(Registries.DAMAGE_TYPE, (context) -> { context.register(ActuallyDamageTypes.ATOMIC_RECONSTRUCTOR, new DamageType("actuallyadditions.atomic_reconstructor", 0.0F)); }); // We need the BIOME registry to be present, so we can use a biome tag, doesn't matter that it's empty - registryBuilder.add(Registries.BIOME, context -> { + registryBuilder.add(Registries.BIOME, $ -> { }); RegistryAccess.Frozen regAccess = RegistryAccess.fromRegistryOfRegistries(BuiltInRegistries.REGISTRY); - return registryBuilder.buildPatch(regAccess, VanillaRegistries.createLookup()); + Cloner.Factory cloner$factory = new Cloner.Factory(); + net.neoforged.neoforge.registries.DataPackRegistriesHooks.getDataPackRegistriesWithDimensions().forEach(data -> data.runWithArguments(cloner$factory::addCodec)); + return registryBuilder.buildPatch(regAccess, VanillaRegistries.createLookup(), cloner$factory); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/data/AdvancementGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/data/AdvancementGenerator.java index 221f18e29..adc475477 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/data/AdvancementGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/data/AdvancementGenerator.java @@ -4,8 +4,10 @@ import de.ellpeck.actuallyadditions.api.ActuallyTags; import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks; import de.ellpeck.actuallyadditions.mod.items.ActuallyItems; import net.minecraft.advancements.Advancement; +import net.minecraft.advancements.AdvancementHolder; +import net.minecraft.advancements.AdvancementType; +import net.minecraft.advancements.CriteriaTriggers; import net.minecraft.advancements.DisplayInfo; -import net.minecraft.advancements.FrameType; import net.minecraft.advancements.critereon.ImpossibleTrigger; import net.minecraft.advancements.critereon.InventoryChangeTrigger; import net.minecraft.advancements.critereon.ItemPredicate; @@ -13,37 +15,38 @@ import net.minecraft.core.HolderLookup; import net.minecraft.data.PackOutput; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; -import net.minecraftforge.common.data.ExistingFileHelper; -import net.minecraftforge.common.data.ForgeAdvancementProvider; +import net.neoforged.neoforge.common.data.AdvancementProvider; +import net.neoforged.neoforge.common.data.ExistingFileHelper; import java.util.List; +import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.function.Consumer; -public class AdvancementGenerator extends ForgeAdvancementProvider { +public class AdvancementGenerator extends AdvancementProvider { public AdvancementGenerator(PackOutput packOutput, CompletableFuture registries, ExistingFileHelper existingFileHelper) { super(packOutput, registries, existingFileHelper, List.of(new ActuallyAdvancementGenerator())); } public static class ActuallyAdvancementGenerator implements AdvancementGenerator { @Override - public void generate(HolderLookup.Provider registries, Consumer consumer, ExistingFileHelper existingFileHelper) { - Advancement root = Advancement.Builder.advancement() + public void generate(HolderLookup.Provider registries, Consumer consumer, ExistingFileHelper existingFileHelper) { + AdvancementHolder root = Advancement.Builder.advancement() .display(new DisplayInfo(ActuallyItems.ITEM_BOOKLET.get().getDefaultInstance(), Component.translatable("achievement.actuallyadditions.openBooklet"), Component.translatable("achievement.actuallyadditions.openBooklet.desc"), - new ResourceLocation("textures/gui/advancements/backgrounds/stone.png"), FrameType.TASK, true, true, false)) - .addCriterion("right_click", new ImpossibleTrigger.TriggerInstance()) + Optional.of(new ResourceLocation("textures/gui/advancements/backgrounds/stone.png")), AdvancementType.TASK, true, true, false)) + .addCriterion("right_click", CriteriaTriggers.IMPOSSIBLE.createCriterion(new ImpossibleTrigger.TriggerInstance())) .save(consumer, "actuallyadditions:root"); //TODO: Underwater Treasure Chest Advancement? - Advancement phantomFace = Advancement.Builder.advancement() + AdvancementHolder phantomFace = Advancement.Builder.advancement() .parent(root) .display(new DisplayInfo(ActuallyBlocks.PHANTOM_ITEMFACE.get().asItem().getDefaultInstance(), Component.translatable("achievement.actuallyadditions.craftPhantomface"), Component.translatable("achievement.actuallyadditions.craftPhantomface.desc"), - new ResourceLocation("textures/blocks/stone.png"), FrameType.TASK, true, true, false)) + Optional.of(new ResourceLocation("textures/blocks/stone.png")), AdvancementType.TASK, true, true, false)) .addCriterion("phantom_face", InventoryChangeTrigger.TriggerInstance.hasItems(ActuallyBlocks.PHANTOM_ITEMFACE.get())) .save(consumer, "actuallyadditions:craft_phantom_face"); @@ -53,7 +56,7 @@ public class AdvancementGenerator extends ForgeAdvancementProvider { .display(new DisplayInfo(ActuallyBlocks.PHANTOM_LIQUIFACE.get().asItem().getDefaultInstance(), Component.translatable("achievement.actuallyadditions.craftLiquiface"), Component.translatable("achievement.actuallyadditions.craftLiquiface.desc"), - null, FrameType.TASK, true, true, false)) + null, AdvancementType.TASK, true, true, false)) .addCriterion("liquiface", InventoryChangeTrigger.TriggerInstance.hasItems(ActuallyBlocks.PHANTOM_LIQUIFACE.get())) .save(consumer, "actuallyadditions:craft_liquiface"); @@ -62,17 +65,17 @@ public class AdvancementGenerator extends ForgeAdvancementProvider { .display(new DisplayInfo(ActuallyBlocks.PHANTOM_ENERGYFACE.get().asItem().getDefaultInstance(), Component.translatable("achievement.actuallyadditions.craftEnergyface"), Component.translatable("achievement.actuallyadditions.craftEnergyface.desc"), - null, FrameType.TASK, true, true, false)) + null, AdvancementType.TASK, true, true, false)) .addCriterion("energyface", InventoryChangeTrigger.TriggerInstance.hasItems(ActuallyBlocks.PHANTOM_ENERGYFACE.get())) .save(consumer, "actuallyadditions:craft_energyface"); - Advancement coalGenerator = Advancement.Builder.advancement() + AdvancementHolder coalGenerator = Advancement.Builder.advancement() .parent(root) .display(new DisplayInfo(ActuallyBlocks.COAL_GENERATOR.get().asItem().getDefaultInstance(), Component.translatable("achievement.actuallyadditions.craftCoalGen"), Component.translatable("achievement.actuallyadditions.craftCoalGen.desc"), - null, FrameType.TASK, true, true, false)) + null, AdvancementType.TASK, true, true, false)) .addCriterion("coal_generator", InventoryChangeTrigger.TriggerInstance.hasItems(ActuallyBlocks.COAL_GENERATOR.get())) .save(consumer, "actuallyadditions:craft_coal_generator"); @@ -81,16 +84,16 @@ public class AdvancementGenerator extends ForgeAdvancementProvider { .display(new DisplayInfo(ActuallyBlocks.LEAF_GENERATOR.get().asItem().getDefaultInstance(), Component.translatable("achievement.actuallyadditions.craftLeafGen"), Component.translatable("achievement.actuallyadditions.craftLeafGen.desc"), - null, FrameType.TASK, true, true, false)) + null, AdvancementType.TASK, true, true, false)) .addCriterion("leaf_generator", InventoryChangeTrigger.TriggerInstance.hasItems(ActuallyBlocks.LEAF_GENERATOR.get())) .save(consumer, "actuallyadditions:craft_leaf_generator"); - Advancement coffeeBeans = Advancement.Builder.advancement() + AdvancementHolder coffeeBeans = Advancement.Builder.advancement() .parent(coalGenerator) .display(new DisplayInfo(ActuallyItems.COFFEE_BEANS.get().getDefaultInstance(), Component.translatable("achievement.actuallyadditions.pickUpCoffee"), Component.translatable("achievement.actuallyadditions.pickUpCoffee.desc"), - null, FrameType.TASK, true, true, false)) + null, AdvancementType.TASK, true, true, false)) .addCriterion("coffee_beans", InventoryChangeTrigger.TriggerInstance.hasItems(ActuallyItems.COFFEE_BEANS.get())) .save(consumer, "actuallyadditions:pickup_coffee"); @@ -99,25 +102,25 @@ public class AdvancementGenerator extends ForgeAdvancementProvider { .display(new DisplayInfo(ActuallyBlocks.COFFEE_MACHINE.get().asItem().getDefaultInstance(), Component.translatable("achievement.actuallyadditions.craftCoffeeMachine"), Component.translatable("achievement.actuallyadditions.craftCoffeeMachine.desc"), - null, FrameType.TASK, true, true, false)) + null, AdvancementType.TASK, true, true, false)) .addCriterion("coffee_machine", InventoryChangeTrigger.TriggerInstance.hasItems(ActuallyBlocks.COFFEE_MACHINE.get())) .save(consumer, "actuallyadditions:craft_coffee_machine"); - Advancement reconstructor = Advancement.Builder.advancement() + AdvancementHolder reconstructor = Advancement.Builder.advancement() .parent(coalGenerator) .display(new DisplayInfo(ActuallyBlocks.ATOMIC_RECONSTRUCTOR.get().asItem().getDefaultInstance(), Component.translatable("achievement.actuallyadditions.craftReconstructor"), Component.translatable("achievement.actuallyadditions.craftReconstructor.desc"), - null, FrameType.TASK, true, true, false)) + null, AdvancementType.TASK, true, true, false)) .addCriterion("atomic_reconstructor", InventoryChangeTrigger.TriggerInstance.hasItems(ActuallyBlocks.ATOMIC_RECONSTRUCTOR.get())) .save(consumer, "actuallyadditions:craft_reconstructor"); - Advancement makeFirstCrystal = Advancement.Builder.advancement() + AdvancementHolder makeFirstCrystal = Advancement.Builder.advancement() .parent(reconstructor) .display(new DisplayInfo(ActuallyItems.EMERADIC_CRYSTAL.get().getDefaultInstance(), Component.translatable("achievement.actuallyadditions.makeCrystal"), Component.translatable("achievement.actuallyadditions.makeCrystal.desc"), - null, FrameType.TASK, true, true, false)) + null, AdvancementType.TASK, true, true, false)) .addCriterion("crystal", InventoryChangeTrigger.TriggerInstance.hasItems( ItemPredicate.Builder.item().of(ActuallyTags.Items.CRYSTALS).build()) ) @@ -128,82 +131,82 @@ public class AdvancementGenerator extends ForgeAdvancementProvider { .display(new DisplayInfo(ActuallyBlocks.EMPOWERER.get().asItem().getDefaultInstance(), Component.translatable("achievement.actuallyadditions.craftEmpowerer"), Component.translatable("achievement.actuallyadditions.craftEmpowerer.desc"), - null, FrameType.TASK, true, true, false)) + null, AdvancementType.TASK, true, true, false)) .addCriterion("empowerer", InventoryChangeTrigger.TriggerInstance.hasItems(ActuallyBlocks.EMPOWERER.get())) .save(consumer, "actuallyadditions:craft_empowerer"); - Advancement craftCrusher = Advancement.Builder.advancement() + AdvancementHolder craftCrusher = Advancement.Builder.advancement() .parent(reconstructor) .display(new DisplayInfo(ActuallyBlocks.CRUSHER.get().asItem().getDefaultInstance(), Component.translatable("achievement.actuallyadditions.craftCrusher"), Component.translatable("achievement.actuallyadditions.craftCrusher.desc"), - null, FrameType.TASK, true, true, false)) + null, AdvancementType.TASK, true, true, false)) .addCriterion("crystal", InventoryChangeTrigger.TriggerInstance.hasItems( ItemPredicate.Builder.item().of(ActuallyBlocks.CRUSHER.get()).build()) ) .save(consumer, "actuallyadditions:craft_crusher"); - Advancement craftDoubleCrusher = Advancement.Builder.advancement() + AdvancementHolder craftDoubleCrusher = Advancement.Builder.advancement() .parent(craftCrusher) .display(new DisplayInfo(ActuallyBlocks.CRUSHER_DOUBLE.get().asItem().getDefaultInstance(), Component.translatable("achievement.actuallyadditions.craftDoubleCrusher"), Component.translatable("achievement.actuallyadditions.craftDoubleCrusher.desc"), - null, FrameType.TASK, true, true, false)) + null, AdvancementType.TASK, true, true, false)) .addCriterion("crystal", InventoryChangeTrigger.TriggerInstance.hasItems( ItemPredicate.Builder.item().of(ActuallyBlocks.CRUSHER_DOUBLE.get()).build()) ) .save(consumer, "actuallyadditions:craft_double_crusher"); - Advancement craftLaserRelay = Advancement.Builder.advancement() + AdvancementHolder craftLaserRelay = Advancement.Builder.advancement() .parent(reconstructor) .display(new DisplayInfo(ActuallyBlocks.LASER_RELAY.get().asItem().getDefaultInstance(), Component.translatable("achievement.actuallyadditions.craftLaserRelay"), Component.translatable("achievement.actuallyadditions.craftLaserRelay.desc"), - null, FrameType.TASK, true, true, false)) + null, AdvancementType.TASK, true, true, false)) .addCriterion("laser_relay", InventoryChangeTrigger.TriggerInstance.hasItems( ItemPredicate.Builder.item().of(ActuallyBlocks.LASER_RELAY.get()).build()) ) .save(consumer, "actuallyadditions:craft_laser_relay"); - Advancement craftLaserRelayAdvanced = Advancement.Builder.advancement() + AdvancementHolder craftLaserRelayAdvanced = Advancement.Builder.advancement() .parent(craftLaserRelay) .display(new DisplayInfo(ActuallyBlocks.LASER_RELAY_ADVANCED.get().asItem().getDefaultInstance(), Component.translatable("achievement.actuallyadditions.craftLaserRelayAdvanced"), Component.translatable("achievement.actuallyadditions.craftLaserRelayAdvanced.desc"), - null, FrameType.TASK, true, true, false)) + null, AdvancementType.TASK, true, true, false)) .addCriterion("laser_relay_advanced", InventoryChangeTrigger.TriggerInstance.hasItems( ItemPredicate.Builder.item().of(ActuallyBlocks.LASER_RELAY_ADVANCED.get()).build()) ) .save(consumer, "actuallyadditions:craft_laser_relay_advanced"); - Advancement craftLaserRelayExtreme = Advancement.Builder.advancement() + AdvancementHolder craftLaserRelayExtreme = Advancement.Builder.advancement() .parent(craftLaserRelayAdvanced) .display(new DisplayInfo(ActuallyBlocks.LASER_RELAY_EXTREME.get().asItem().getDefaultInstance(), Component.translatable("achievement.actuallyadditions.craftLaserRelayExtreme"), Component.translatable("achievement.actuallyadditions.craftLaserRelayExtreme.desc"), - null, FrameType.TASK, true, true, false)) + null, AdvancementType.TASK, true, true, false)) .addCriterion("laser_relay_extreme", InventoryChangeTrigger.TriggerInstance.hasItems( ItemPredicate.Builder.item().of(ActuallyBlocks.LASER_RELAY_EXTREME.get()).build()) ) .save(consumer, "actuallyadditions:craft_laser_relay_extreme"); - Advancement craftLaserRelayItem = Advancement.Builder.advancement() + AdvancementHolder craftLaserRelayItem = Advancement.Builder.advancement() .parent(craftLaserRelay) .display(new DisplayInfo(ActuallyBlocks.LASER_RELAY_ITEM.get().asItem().getDefaultInstance(), Component.translatable("achievement.actuallyadditions.craftLaserRelayItem"), Component.translatable("achievement.actuallyadditions.craftLaserRelayItem.desc"), - null, FrameType.TASK, true, true, false)) + null, AdvancementType.TASK, true, true, false)) .addCriterion("laser_relay_item", InventoryChangeTrigger.TriggerInstance.hasItems( ItemPredicate.Builder.item().of(ActuallyBlocks.LASER_RELAY_ITEM.get()).build()) ) .save(consumer, "actuallyadditions:craft_laser_relay_item"); - Advancement craftItemInterface = Advancement.Builder.advancement() + AdvancementHolder craftItemInterface = Advancement.Builder.advancement() .parent(craftLaserRelay) .display(new DisplayInfo(ActuallyBlocks.ITEM_INTERFACE.get().asItem().getDefaultInstance(), Component.translatable("achievement.actuallyadditions.craftItemInterface"), Component.translatable("achievement.actuallyadditions.craftItemInterface.desc"), - null, FrameType.TASK, true, true, false)) + null, AdvancementType.TASK, true, true, false)) .addCriterion("item_interface", InventoryChangeTrigger.TriggerInstance.hasItems( ItemPredicate.Builder.item().of(ActuallyBlocks.ITEM_INTERFACE.get()).build()) ) diff --git a/src/main/java/de/ellpeck/actuallyadditions/data/BlockRecipeGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/data/BlockRecipeGenerator.java index e6eeb5898..defe709cb 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/data/BlockRecipeGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/data/BlockRecipeGenerator.java @@ -1,26 +1,21 @@ package de.ellpeck.actuallyadditions.data; -import com.google.gson.JsonObject; import de.ellpeck.actuallyadditions.api.ActuallyTags; import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks; import de.ellpeck.actuallyadditions.mod.items.ActuallyItems; -import net.minecraft.data.CachedOutput; import net.minecraft.data.PackOutput; -import net.minecraft.data.recipes.FinishedRecipe; import net.minecraft.data.recipes.RecipeCategory; +import net.minecraft.data.recipes.RecipeOutput; import net.minecraft.data.recipes.RecipeProvider; import net.minecraft.data.recipes.ShapedRecipeBuilder; import net.minecraft.data.recipes.ShapelessRecipeBuilder; import net.minecraft.tags.ItemTags; import net.minecraft.world.item.Items; import net.minecraft.world.level.ItemLike; -import net.minecraftforge.common.Tags; -import org.jetbrains.annotations.Nullable; +import net.neoforged.neoforge.common.Tags; import javax.annotation.Nonnull; import java.util.Arrays; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; public class BlockRecipeGenerator extends RecipeProvider { public BlockRecipeGenerator(PackOutput packOutput) { @@ -28,7 +23,7 @@ public class BlockRecipeGenerator extends RecipeProvider { } @Override - protected void buildRecipes(@Nonnull Consumer consumer) { + protected void buildRecipes(@Nonnull RecipeOutput consumer) { //Battery Box Recipe.shapeless(ActuallyBlocks.BATTERY_BOX.getItem()).ingredients(ActuallyBlocks.ENERGIZER.get(), ActuallyBlocks.ENERVATOR.get(), ActuallyItems.BASIC_COIL.get()).save(consumer); @@ -232,11 +227,11 @@ public class BlockRecipeGenerator extends RecipeProvider { } - @Override - protected @Nullable CompletableFuture saveAdvancement(CachedOutput output, FinishedRecipe finishedRecipe, JsonObject advancementJson) { - return null; - //Nope... maybe later... - } +// @Override //TODO: Flanks do your RecipeOutput wrapper thingy ;) +// protected @Nullable CompletableFuture saveAdvancement(CachedOutput stack, FinishedRecipe finishedRecipe, JsonObject advancementJson) { +// return null; +// //Nope... maybe later... +// } public static class Recipe { public static Shapeless shapeless(ItemLike result) { @@ -255,15 +250,15 @@ public class BlockRecipeGenerator extends RecipeProvider { return new Shaped(result, count); } - public static void stairs(ItemLike result, ItemLike resource, Consumer consumer) { + public static void stairs(ItemLike result, ItemLike resource, RecipeOutput consumer) { Recipe.shaped(result).patternSingleKey('Q', resource, "Q ", "QQ ", "QQQ").save(consumer); } - public static void wall(ItemLike result, ItemLike resource, Consumer consumer) { + public static void wall(ItemLike result, ItemLike resource, RecipeOutput consumer) { Recipe.shaped(result).patternSingleKey('Q', resource, "QQQ", "QQQ").save(consumer); } - public static void slab(ItemLike result, ItemLike resource, Consumer consumer) { + public static void slab(ItemLike result, ItemLike resource, RecipeOutput consumer) { Recipe.shaped(result).patternSingleKey('Q', resource, "QQQ").save(consumer); } @@ -282,7 +277,7 @@ public class BlockRecipeGenerator extends RecipeProvider { } @Override - public void save(Consumer consumer) { + public void save(RecipeOutput consumer) { this.unlockedBy("has_book", has(ActuallyItems.ITEM_BOOKLET.get())); super.save(consumer); } @@ -320,7 +315,7 @@ public class BlockRecipeGenerator extends RecipeProvider { } @Override - public void save(Consumer consumerIn) { + public void save(RecipeOutput consumerIn) { this.unlockedBy("has_book", has(ActuallyItems.ITEM_BOOKLET.get())); super.save(consumerIn); } diff --git a/src/main/java/de/ellpeck/actuallyadditions/data/BlockStateGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/data/BlockStateGenerator.java index 4531b9568..3d9e4bd0c 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/data/BlockStateGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/data/BlockStateGenerator.java @@ -4,6 +4,7 @@ import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks; import de.ellpeck.actuallyadditions.mod.blocks.BlockTinyTorch; import net.minecraft.core.Direction; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.data.PackOutput; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.block.Block; @@ -12,11 +13,10 @@ import net.minecraft.world.level.block.SlabBlock; import net.minecraft.world.level.block.StairBlock; import net.minecraft.world.level.block.WallBlock; import net.minecraft.world.level.block.state.properties.BlockStateProperties; -import net.minecraftforge.client.model.generators.BlockStateProvider; -import net.minecraftforge.client.model.generators.ConfiguredModel; -import net.minecraftforge.client.model.generators.ModelFile; -import net.minecraftforge.common.data.ExistingFileHelper; -import net.minecraftforge.registries.ForgeRegistries; +import net.neoforged.neoforge.client.model.generators.BlockStateProvider; +import net.neoforged.neoforge.client.model.generators.ConfiguredModel; +import net.neoforged.neoforge.client.model.generators.ModelFile; +import net.neoforged.neoforge.common.data.ExistingFileHelper; import java.util.function.Supplier; @@ -210,7 +210,7 @@ public class BlockStateGenerator extends BlockStateProvider { } private void standardBlock(Supplier block) { - ResourceLocation name = ForgeRegistries.BLOCKS.getKey(block.get()); + ResourceLocation name = BuiltInRegistries.BLOCK.getKey(block.get()); ModelFile model = new ModelFile.UncheckedModelFile(modLoc("block/" + name.getPath())); assert name != null; @@ -218,7 +218,7 @@ public class BlockStateGenerator extends BlockStateProvider { } private void standardBlockWithCube(Supplier block) { - ResourceLocation name = ForgeRegistries.BLOCKS.getKey(block.get()); + ResourceLocation name = BuiltInRegistries.BLOCK.getKey(block.get()); assert name != null; ModelFile model = models().cubeAll(name.toString(), modLoc("block/" + name.getPath())); @@ -226,7 +226,7 @@ public class BlockStateGenerator extends BlockStateProvider { } private void buildLitState(Supplier block) { - ResourceLocation name = ForgeRegistries.BLOCKS.getKey(block.get()); + ResourceLocation name = BuiltInRegistries.BLOCK.getKey(block.get()); assert name != null; getVariantBuilder(block.get()) @@ -237,7 +237,7 @@ public class BlockStateGenerator extends BlockStateProvider { } private void fullyDirectionalBlock(Supplier block) { - ResourceLocation name = ForgeRegistries.BLOCKS.getKey(block.get()); + ResourceLocation name = BuiltInRegistries.BLOCK.getKey(block.get()); ModelFile model = new ModelFile.UncheckedModelFile(modLoc("block/" + name.getPath())); ModelFile verModel = new ModelFile.UncheckedModelFile(modLoc("block/" + name.getPath() + "_ver")); @@ -246,7 +246,7 @@ public class BlockStateGenerator extends BlockStateProvider { } private void horizontallyDirectionalBlock(Supplier block) { - ResourceLocation name = ForgeRegistries.BLOCKS.getKey(block.get()); + ResourceLocation name = BuiltInRegistries.BLOCK.getKey(block.get()); ModelFile model = new ModelFile.UncheckedModelFile(modLoc("block/" + name.getPath())); assert name != null; @@ -255,7 +255,7 @@ public class BlockStateGenerator extends BlockStateProvider { private void tinyTorchBlock(Supplier block) { assert block.get() instanceof BlockTinyTorch; - ResourceLocation name = ForgeRegistries.BLOCKS.getKey(block.get()); + ResourceLocation name = BuiltInRegistries.BLOCK.getKey(block.get()); ModelFile model = new ModelFile.UncheckedModelFile(modLoc("block/" + name.getPath())); ModelFile wallModel = new ModelFile.UncheckedModelFile(modLoc("block/" + name.getPath() + "_wall")); diff --git a/src/main/java/de/ellpeck/actuallyadditions/data/BlockTagsGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/data/BlockTagsGenerator.java index e4fc488ac..f1ba1af4a 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/data/BlockTagsGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/data/BlockTagsGenerator.java @@ -6,8 +6,8 @@ import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks; import net.minecraft.core.HolderLookup; import net.minecraft.data.PackOutput; import net.minecraft.tags.BlockTags; -import net.minecraftforge.common.data.BlockTagsProvider; -import net.minecraftforge.common.data.ExistingFileHelper; +import net.neoforged.neoforge.common.data.BlockTagsProvider; +import net.neoforged.neoforge.common.data.ExistingFileHelper; import javax.annotation.Nullable; import java.util.concurrent.CompletableFuture; diff --git a/src/main/java/de/ellpeck/actuallyadditions/data/ColorChangeGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/data/ColorChangeGenerator.java index a728efde8..e22d39bf6 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/data/ColorChangeGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/data/ColorChangeGenerator.java @@ -1,24 +1,19 @@ package de.ellpeck.actuallyadditions.data; -import com.google.gson.JsonObject; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks; import de.ellpeck.actuallyadditions.mod.crafting.ColorChangeRecipe; -import net.minecraft.data.CachedOutput; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.data.PackOutput; -import net.minecraft.data.recipes.FinishedRecipe; +import net.minecraft.data.recipes.RecipeOutput; import net.minecraft.data.recipes.RecipeProvider; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.level.ItemLike; -import net.minecraftforge.registries.ForgeRegistries; -import org.jetbrains.annotations.Nullable; import javax.annotation.Nonnull; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; public class ColorChangeGenerator extends RecipeProvider { public ColorChangeGenerator(PackOutput packOutput) { @@ -30,13 +25,14 @@ public class ColorChangeGenerator extends RecipeProvider { return "Color Change " + super.getName(); } - @Override - protected @Nullable CompletableFuture saveAdvancement(CachedOutput output, FinishedRecipe finishedRecipe, JsonObject advancementJson) { - return null; //Nope... - } +// @Override //TODO: Flanks do your RecipeOutput wrapper thingy ;) +// protected @Nullable CompletableFuture saveAdvancement(CachedOutput stack, FinishedRecipe finishedRecipe, JsonObject advancementJson) { +// return null; +// //Nope... maybe later... +// } @Override - protected void buildRecipes(@Nonnull Consumer consumer) { + protected void buildRecipes(@Nonnull RecipeOutput consumer) { buildWool(consumer); buildStainedGlass(consumer); buildStainedGlassPane(consumer); @@ -47,7 +43,7 @@ public class ColorChangeGenerator extends RecipeProvider { buildDye(consumer); } - private void buildWool(@Nonnull Consumer c) { + private void buildWool(@Nonnull RecipeOutput c) { //Wool changeColor(c, Items.WHITE_WOOL, Items.BLACK_WOOL); changeColor(c, Items.ORANGE_WOOL, Items.WHITE_WOOL); @@ -67,7 +63,7 @@ public class ColorChangeGenerator extends RecipeProvider { changeColor(c, Items.BLACK_WOOL, Items.RED_WOOL); } - private void buildStainedGlass(@Nonnull Consumer c) { + private void buildStainedGlass(@Nonnull RecipeOutput c) { changeColor(c, Items.WHITE_STAINED_GLASS, Items.BLACK_STAINED_GLASS); changeColor(c, Items.ORANGE_STAINED_GLASS, Items.WHITE_STAINED_GLASS); changeColor(c, Items.MAGENTA_STAINED_GLASS, Items.ORANGE_STAINED_GLASS); @@ -86,7 +82,7 @@ public class ColorChangeGenerator extends RecipeProvider { changeColor(c, Items.BLACK_STAINED_GLASS, Items.RED_STAINED_GLASS); } - private void buildStainedGlassPane(@Nonnull Consumer c) { + private void buildStainedGlassPane(@Nonnull RecipeOutput c) { changeColor(c, Items.WHITE_STAINED_GLASS_PANE, Items.BLACK_STAINED_GLASS_PANE); changeColor(c, Items.ORANGE_STAINED_GLASS_PANE, Items.WHITE_STAINED_GLASS_PANE); changeColor(c, Items.MAGENTA_STAINED_GLASS_PANE, Items.ORANGE_STAINED_GLASS_PANE); @@ -105,7 +101,7 @@ public class ColorChangeGenerator extends RecipeProvider { changeColor(c, Items.BLACK_STAINED_GLASS_PANE, Items.RED_STAINED_GLASS_PANE); } - private void buildTerracotta(@Nonnull Consumer c) { + private void buildTerracotta(@Nonnull RecipeOutput c) { changeColor(c, Items.WHITE_TERRACOTTA, Items.BLACK_TERRACOTTA); changeColor(c, Items.ORANGE_TERRACOTTA, Items.WHITE_TERRACOTTA); changeColor(c, Items.MAGENTA_TERRACOTTA, Items.ORANGE_TERRACOTTA); @@ -124,7 +120,7 @@ public class ColorChangeGenerator extends RecipeProvider { changeColor(c, Items.BLACK_TERRACOTTA, Items.RED_TERRACOTTA); } - private void buildGlazedTerracotta(@Nonnull Consumer c) { + private void buildGlazedTerracotta(@Nonnull RecipeOutput c) { changeColor(c, Items.WHITE_GLAZED_TERRACOTTA, Items.BLACK_GLAZED_TERRACOTTA); changeColor(c, Items.ORANGE_GLAZED_TERRACOTTA, Items.WHITE_GLAZED_TERRACOTTA); changeColor(c, Items.MAGENTA_GLAZED_TERRACOTTA, Items.ORANGE_GLAZED_TERRACOTTA); @@ -143,7 +139,7 @@ public class ColorChangeGenerator extends RecipeProvider { changeColor(c, Items.BLACK_GLAZED_TERRACOTTA, Items.RED_GLAZED_TERRACOTTA); } - private void buildCarpet(@Nonnull Consumer c) { + private void buildCarpet(@Nonnull RecipeOutput c) { changeColor(c, Items.WHITE_CARPET, Items.BLACK_CARPET); changeColor(c, Items.ORANGE_CARPET, Items.WHITE_CARPET); changeColor(c, Items.MAGENTA_CARPET, Items.ORANGE_CARPET); @@ -162,7 +158,7 @@ public class ColorChangeGenerator extends RecipeProvider { changeColor(c, Items.BLACK_CARPET, Items.RED_CARPET); } - private void buildLamps(@Nonnull Consumer c) { + private void buildLamps(@Nonnull RecipeOutput c) { changeColor(c, ActuallyBlocks.LAMP_WHITE.getItem(), ActuallyBlocks.LAMP_BLACK.getItem()); changeColor(c, ActuallyBlocks.LAMP_ORANGE.getItem(), ActuallyBlocks.LAMP_WHITE.getItem()); changeColor(c, ActuallyBlocks.LAMP_MAGENTA.getItem(), ActuallyBlocks.LAMP_ORANGE.getItem()); @@ -181,7 +177,7 @@ public class ColorChangeGenerator extends RecipeProvider { changeColor(c, ActuallyBlocks.LAMP_BLACK.getItem(), ActuallyBlocks.LAMP_RED.getItem()); } - private void buildDye(@Nonnull Consumer c) { + private void buildDye(@Nonnull RecipeOutput c) { changeColor(c, Items.WHITE_DYE, Items.BLACK_DYE); changeColor(c, Items.ORANGE_DYE, Items.WHITE_DYE); changeColor(c, Items.MAGENTA_DYE, Items.ORANGE_DYE); @@ -201,16 +197,16 @@ public class ColorChangeGenerator extends RecipeProvider { } - private void changeColor(Consumer consumer, ItemLike output, Ingredient input) { - consumer.accept(new ColorChangeRecipe.Result(new ResourceLocation(ActuallyAdditions.MODID, "colorchange/" + ForgeRegistries.ITEMS.getKey(output.asItem()).getPath()), - input, output)); + private void changeColor(RecipeOutput consumer, ItemLike output, Ingredient input) { + consumer.accept(new ResourceLocation(ActuallyAdditions.MODID, "colorchange/" + BuiltInRegistries.ITEM.getKey(output.asItem()).getPath()), + new ColorChangeRecipe(output.asItem().getDefaultInstance(), input), null); } - private void changeColor(Consumer consumer, ItemLike output, ItemLike input) { - consumer.accept(new ColorChangeRecipe.Result(new ResourceLocation(ActuallyAdditions.MODID, "colorchange/" + ForgeRegistries.ITEMS.getKey(output.asItem()).getPath()), - Ingredient.of(input), output)); + private void changeColor(RecipeOutput consumer, ItemLike output, ItemLike input) { + consumer.accept(new ResourceLocation(ActuallyAdditions.MODID, "colorchange/" + BuiltInRegistries.ITEM.getKey(output.asItem()).getPath()), + new ColorChangeRecipe(output.asItem().getDefaultInstance(), Ingredient.of(input)), null); } - private void changeColor(Consumer consumer, ItemLike output, ItemStack input) { - consumer.accept(new ColorChangeRecipe.Result(new ResourceLocation(ActuallyAdditions.MODID, "colorchange/" + ForgeRegistries.ITEMS.getKey(output.asItem()).getPath()), - Ingredient.of(input), output)); + private void changeColor(RecipeOutput consumer, ItemLike output, ItemStack input) { + consumer.accept(new ResourceLocation(ActuallyAdditions.MODID, "colorchange/" + BuiltInRegistries.ITEM.getKey(output.asItem()).getPath()), + new ColorChangeRecipe(output.asItem().getDefaultInstance(), Ingredient.of(input)), null); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/data/CrushingRecipeGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/data/CrushingRecipeGenerator.java index ae9c23b91..312927a85 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/data/CrushingRecipeGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/data/CrushingRecipeGenerator.java @@ -1,19 +1,14 @@ package de.ellpeck.actuallyadditions.data; -import com.google.gson.JsonObject; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.crafting.CrushingRecipe; -import net.minecraft.data.CachedOutput; import net.minecraft.data.PackOutput; -import net.minecraft.data.recipes.FinishedRecipe; +import net.minecraft.data.recipes.RecipeOutput; import net.minecraft.data.recipes.RecipeProvider; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.item.crafting.Ingredient; -import org.jetbrains.annotations.Nullable; - -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; public class CrushingRecipeGenerator extends RecipeProvider { public CrushingRecipeGenerator(PackOutput packOutput) { @@ -25,14 +20,15 @@ public class CrushingRecipeGenerator extends RecipeProvider { return "Crushing " + super.getName(); } - @Override - protected @Nullable CompletableFuture saveAdvancement(CachedOutput output, FinishedRecipe finishedRecipe, JsonObject advancementJson) { - return null; //Nope... - } +// @Override //TODO: Flanks do your RecipeOutput wrapper thingy ;) +// protected @Nullable CompletableFuture saveAdvancement(CachedOutput stack, FinishedRecipe finishedRecipe, JsonObject advancementJson) { +// return null; +// //Nope... maybe later... +// } @Override - protected void buildRecipes(Consumer consumer) { - consumer.accept(new CrushingRecipe.Result(new ResourceLocation(ActuallyAdditions.MODID, "crushing/bone_crusher"), - Ingredient.of(Items.BONE), Items.BONE_MEAL, 6, 1.0f , Items.AIR, 0, 0.0f)); + protected void buildRecipes(RecipeOutput consumer) { + CrushingRecipe recipe = new CrushingRecipe(Ingredient.of(Items.BONE), new ItemStack(Items.BONE_MEAL, 6), 1.0f, ItemStack.EMPTY, 0.0f); + consumer.accept(new ResourceLocation(ActuallyAdditions.MODID, "crushing/iron_crusher"), recipe, null); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/data/DamageTypeTagsGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/data/DamageTypeTagsGenerator.java index 017acd3d1..e4bfd836b 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/data/DamageTypeTagsGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/data/DamageTypeTagsGenerator.java @@ -6,7 +6,7 @@ import net.minecraft.core.HolderLookup; import net.minecraft.data.PackOutput; import net.minecraft.data.tags.DamageTypeTagsProvider; import net.minecraft.tags.DamageTypeTags; -import net.minecraftforge.common.data.ExistingFileHelper; +import net.neoforged.neoforge.common.data.ExistingFileHelper; import org.jetbrains.annotations.Nullable; import java.util.concurrent.CompletableFuture; diff --git a/src/main/java/de/ellpeck/actuallyadditions/data/EmpoweringRecipeGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/data/EmpoweringRecipeGenerator.java index 262e19f08..317f3d744 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/data/EmpoweringRecipeGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/data/EmpoweringRecipeGenerator.java @@ -1,14 +1,14 @@ package de.ellpeck.actuallyadditions.data; -import com.google.gson.JsonObject; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks; import de.ellpeck.actuallyadditions.mod.crafting.EmpowererRecipe; import de.ellpeck.actuallyadditions.mod.items.ActuallyItems; import de.ellpeck.actuallyadditions.mod.items.metalists.Crystals; -import net.minecraft.data.CachedOutput; +import net.minecraft.core.NonNullList; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.data.PackOutput; -import net.minecraft.data.recipes.FinishedRecipe; +import net.minecraft.data.recipes.RecipeOutput; import net.minecraft.data.recipes.RecipeProvider; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.ItemTags; @@ -18,14 +18,7 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.level.ItemLike; -import net.minecraftforge.common.Tags; -import net.minecraftforge.registries.ForgeRegistries; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; +import net.neoforged.neoforge.common.Tags; public class EmpoweringRecipeGenerator extends RecipeProvider { public EmpoweringRecipeGenerator(PackOutput packOutput) { @@ -37,13 +30,14 @@ public class EmpoweringRecipeGenerator extends RecipeProvider { return "Empowering " + super.getName(); } - @Override - protected @Nullable CompletableFuture saveAdvancement(CachedOutput output, FinishedRecipe finishedRecipe, JsonObject advancementJson) { - return null; //Nope... - } +// @Override //TODO: Flanks do your RecipeOutput wrapper thingy ;) +// protected @Nullable CompletableFuture saveAdvancement(CachedOutput stack, FinishedRecipe finishedRecipe, JsonObject advancementJson) { +// return null; +// //Nope... maybe later... +// } @Override - protected void buildRecipes(Consumer consumer) { + protected void buildRecipes(RecipeOutput consumer) { EmpoweringBuilder.builder(ActuallyItems.EMPOWERED_RESTONIA_CRYSTAL.get(), ActuallyItems.RESTONIA_CRYSTAL.get(), 5000, 50, Crystals.REDSTONE.conversionColorParticles) .addModifier(Tags.Items.DYES_RED) .addModifier(Items.NETHER_BRICK) @@ -124,7 +118,7 @@ public class EmpoweringRecipeGenerator extends RecipeProvider { private final int energy; private final int time; private final int color; - private final List modifiers = new ArrayList<>(); + private final NonNullList modifiers = NonNullList.create(); public EmpoweringBuilder(ItemLike resultIn, Ingredient baseIn, int energyIn, int timeIn, int colorIn) { result = resultIn.asItem(); @@ -140,14 +134,14 @@ public class EmpoweringRecipeGenerator extends RecipeProvider { public EmpoweringBuilder addModifier(ItemLike input) { if (modifiers.size() >= 4) - throw new IllegalStateException("too many modifiers for empowering recipe, input: " + ForgeRegistries.ITEMS.getKey(input.asItem())); + throw new IllegalStateException("too many modifiers for empowering recipe, input: " + BuiltInRegistries.ITEM.getKey(input.asItem())); modifiers.add(Ingredient.of(input)); return this; } public EmpoweringBuilder addModifier(ItemStack input) { if (modifiers.size() >= 4) - throw new IllegalStateException("too many modifiers for empowering recipe, input: " + ForgeRegistries.ITEMS.getKey(input.getItem())); + throw new IllegalStateException("too many modifiers for empowering recipe, input: " + BuiltInRegistries.ITEM.getKey(input.getItem())); modifiers.add(Ingredient.of(input)); return this; } @@ -159,17 +153,21 @@ public class EmpoweringRecipeGenerator extends RecipeProvider { return this; } - public void save(Consumer consumer, ResourceLocation name) { + public void save(RecipeOutput consumer, ResourceLocation name) { if (modifiers.size() != 4) throw new IllegalStateException("invalid modifier count: " + modifiers.size() + ", recipe: " + name.toString()); - consumer.accept(new EmpowererRecipe.Result(name, result, base, modifiers.get(0), modifiers.get(1), modifiers.get(2), modifiers.get(3), energy, color, time)); + + EmpowererRecipe recipe = new EmpowererRecipe(result.getDefaultInstance(), base, modifiers, energy, color, time); + consumer.accept(name, recipe, null); } - public void save(Consumer consumer, String name) { + public void save(RecipeOutput consumer, String name) { ResourceLocation res = new ResourceLocation(ActuallyAdditions.MODID, "empowering/" + name); if (modifiers.size() != 4) throw new IllegalStateException("invalid modifier count: " + modifiers.size() + ", recipe: " + res); - consumer.accept(new EmpowererRecipe.Result(res, result, base, modifiers.get(0), modifiers.get(1), modifiers.get(2), modifiers.get(3), energy, color, time)); + + EmpowererRecipe recipe = new EmpowererRecipe(result.getDefaultInstance(), base, modifiers, energy, color, time); + consumer.accept(res, recipe, null); } } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/data/FuelRecipeGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/data/FuelRecipeGenerator.java index cfc0b60cd..dd69caa9d 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/data/FuelRecipeGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/data/FuelRecipeGenerator.java @@ -1,26 +1,21 @@ package de.ellpeck.actuallyadditions.data; -import com.google.gson.JsonObject; import de.ellpeck.actuallyadditions.api.ActuallyTags; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.crafting.LiquidFuelRecipe; import de.ellpeck.actuallyadditions.mod.crafting.SolidFuelRecipe; import de.ellpeck.actuallyadditions.mod.fluids.InitFluids; -import net.minecraft.data.CachedOutput; import net.minecraft.data.PackOutput; -import net.minecraft.data.recipes.FinishedRecipe; +import net.minecraft.data.recipes.RecipeOutput; import net.minecraft.data.recipes.RecipeProvider; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.TagKey; import net.minecraft.world.item.Item; import net.minecraft.world.item.Items; import net.minecraft.world.item.crafting.Ingredient; -import net.minecraftforge.fluids.FluidStack; -import org.jetbrains.annotations.Nullable; +import net.neoforged.neoforge.fluids.FluidStack; import javax.annotation.Nonnull; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; public class FuelRecipeGenerator extends RecipeProvider { public FuelRecipeGenerator(PackOutput packOutput) { @@ -32,13 +27,14 @@ public class FuelRecipeGenerator extends RecipeProvider { return "Fuel " + super.getName(); } - @Override - protected @Nullable CompletableFuture saveAdvancement(CachedOutput output, FinishedRecipe finishedRecipe, JsonObject advancementJson) { - return null; //Nope... - } +// @Override //TODO: Flanks do your RecipeOutput wrapper thingy ;) +// protected @Nullable CompletableFuture saveAdvancement(CachedOutput stack, FinishedRecipe finishedRecipe, JsonObject advancementJson) { +// return null; +// //Nope... maybe later... +// } @Override - protected void buildRecipes(@Nonnull Consumer consumer) { + protected void buildRecipes(@Nonnull RecipeOutput consumer) { addSolid(consumer, "coal", Items.COAL, 32000, 1600); addSolid(consumer, "stick", Items.STICK, 2000, 100); addSolid(consumer, "tiny-coal", ActuallyTags.Items.TINY_COALS, 4000, 200); @@ -46,26 +42,29 @@ public class FuelRecipeGenerator extends RecipeProvider { addSolid(consumer, "coal-block", Items.COAL_BLOCK, 320000, 16000); addSolid(consumer, "lava", Items.LAVA_BUCKET, 400000, 20000); - consumer.accept(new LiquidFuelRecipe.Result(new ResourceLocation(ActuallyAdditions.MODID, "liquid_fuel/canola_oil"), - new FluidStack(InitFluids.CANOLA_OIL.get(), 50), 4000, 100)); + consumer.accept(new ResourceLocation(ActuallyAdditions.MODID, "liquid_fuel/canola_oil"), new LiquidFuelRecipe( + new FluidStack(InitFluids.CANOLA_OIL.get(), 50), 4000, 100), null); - consumer.accept(new LiquidFuelRecipe.Result(new ResourceLocation(ActuallyAdditions.MODID, "liquid_fuel/refined_canola_oil"), - new FluidStack(InitFluids.REFINED_CANOLA_OIL.get(), 50), 9600, 120)); + consumer.accept(new ResourceLocation(ActuallyAdditions.MODID, "liquid_fuel/refined_canola_oil"), new LiquidFuelRecipe( + new FluidStack(InitFluids.REFINED_CANOLA_OIL.get(), 50), 9600, 120), null); - consumer.accept(new LiquidFuelRecipe.Result(new ResourceLocation(ActuallyAdditions.MODID, "liquid_fuel/crystallized_canola_oil"), - new FluidStack(InitFluids.CRYSTALLIZED_OIL.get(), 50), 28000, 280)); + consumer.accept(new ResourceLocation(ActuallyAdditions.MODID, "liquid_fuel/crystallized_canola_oil"),new LiquidFuelRecipe( + new FluidStack(InitFluids.CRYSTALLIZED_OIL.get(), 50), 28000, 280), null); - consumer.accept(new LiquidFuelRecipe.Result(new ResourceLocation(ActuallyAdditions.MODID, "liquid_fuel/empowered_canola_oil"), - new FluidStack(InitFluids.EMPOWERED_OIL.get(), 50), 48000, 400)); + consumer.accept(new ResourceLocation(ActuallyAdditions.MODID, "liquid_fuel/empowered_canola_oil"), new LiquidFuelRecipe( + new FluidStack(InitFluids.EMPOWERED_OIL.get(), 50), 48000, 400), null); } - private void addSolid(Consumer consumer, String name, Item item, int energy, int burnTime) { - consumer.accept(new SolidFuelRecipe.Result(new ResourceLocation(ActuallyAdditions.MODID, "solid_fuel/"+name), Ingredient.of(item), energy, burnTime)); + private void addSolid(RecipeOutput consumer, String name, Item item, int energy, int burnTime) { + ResourceLocation id = new ResourceLocation(ActuallyAdditions.MODID, "solid_fuel/"+name); + consumer.accept(id, new SolidFuelRecipe(Ingredient.of(item), energy, burnTime), null); } - private void addSolid(Consumer consumer, String name, Ingredient item, int energy, int burnTime) { - consumer.accept(new SolidFuelRecipe.Result(new ResourceLocation(ActuallyAdditions.MODID, "solid_fuel/"+name), item, energy, burnTime)); + private void addSolid(RecipeOutput consumer, String name, Ingredient item, int energy, int burnTime) { + ResourceLocation id = new ResourceLocation(ActuallyAdditions.MODID, "solid_fuel/"+name); + consumer.accept(id, new SolidFuelRecipe(item, energy, burnTime), null); } - private void addSolid(Consumer consumer, String name, TagKey tag, int energy, int burnTime) { - consumer.accept(new SolidFuelRecipe.Result(new ResourceLocation(ActuallyAdditions.MODID, "solid_fuel/"+name), Ingredient.of(tag), energy, burnTime)); + private void addSolid(RecipeOutput consumer, String name, TagKey tag, int energy, int burnTime) { + ResourceLocation id = new ResourceLocation(ActuallyAdditions.MODID, "solid_fuel/"+name); + consumer.accept(id, new SolidFuelRecipe(Ingredient.of(tag), energy, burnTime), null); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/data/ItemModelGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/data/ItemModelGenerator.java index 5497ef1af..5ec5cfa20 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/data/ItemModelGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/data/ItemModelGenerator.java @@ -6,17 +6,17 @@ import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks; import de.ellpeck.actuallyadditions.mod.fluids.FluidAA; import de.ellpeck.actuallyadditions.mod.fluids.InitFluids; import de.ellpeck.actuallyadditions.mod.items.ActuallyItems; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.data.PackOutput; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.Item; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.WallBlock; -import net.minecraftforge.client.model.generators.ItemModelProvider; -import net.minecraftforge.client.model.generators.ModelFile; -import net.minecraftforge.client.model.generators.loaders.DynamicFluidContainerModelBuilder; -import net.minecraftforge.common.data.ExistingFileHelper; -import net.minecraftforge.registries.ForgeRegistries; -import net.minecraftforge.registries.RegistryObject; +import net.neoforged.neoforge.client.model.generators.ItemModelProvider; +import net.neoforged.neoforge.client.model.generators.ModelFile; +import net.neoforged.neoforge.client.model.generators.loaders.DynamicFluidContainerModelBuilder; +import net.neoforged.neoforge.common.data.ExistingFileHelper; +import net.neoforged.neoforge.registries.DeferredHolder; import java.util.Set; import java.util.function.Supplier; @@ -71,16 +71,16 @@ public class ItemModelGenerator extends ItemModelProvider { .override().predicate(new ResourceLocation(ActuallyAdditions.MODID, "snail"), 1F) .model(getBuilder("snail").parent(getExistingFile(mcLoc("item/handheld"))).texture("layer0", "item/snail")).end();*/ - String torchPath = ForgeRegistries.ITEMS.getKey(ActuallyBlocks.TINY_TORCH.getItem()).getPath(); + String torchPath = BuiltInRegistries.ITEM.getKey(ActuallyBlocks.TINY_TORCH.getItem()).getPath(); singleTexture(torchPath, mcLoc("item/generated"), "layer0", modLoc("block/" + torchPath)); } private void generateBucket(FluidAA fluidSupplier) { - withExistingParent(ForgeRegistries.ITEMS.getKey(fluidSupplier.getBucket()).getPath(), "forge:item/bucket") + withExistingParent(BuiltInRegistries.ITEM.getKey(fluidSupplier.getBucket()).getPath(), "forge:item/bucket") .customLoader((builder, template) -> DynamicFluidContainerModelBuilder.begin(builder, template).fluid(fluidSupplier.get())); } - private void registerBlockModel(RegistryObject block) { + private void registerBlockModel(DeferredHolder block) { String path = block.getId().getPath(); if (block.get() instanceof WallBlock) { String name = path; @@ -93,7 +93,7 @@ public class ItemModelGenerator extends ItemModelProvider { } private void simpleItem(Supplier item) { - String path = ForgeRegistries.ITEMS.getKey(item.get()).getPath(); + String path = BuiltInRegistries.ITEM.getKey(item.get()).getPath(); singleTexture(path, mcLoc("item/handheld"), "layer0", modLoc("item/" + path)); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/data/ItemRecipeGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/data/ItemRecipeGenerator.java index bbd7b87ab..05227cc68 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/data/ItemRecipeGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/data/ItemRecipeGenerator.java @@ -1,17 +1,13 @@ package de.ellpeck.actuallyadditions.data; -import com.google.gson.JsonObject; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks; import de.ellpeck.actuallyadditions.mod.config.conditions.BoolConfigCondition; -import de.ellpeck.actuallyadditions.mod.crafting.ActuallyRecipes; -import de.ellpeck.actuallyadditions.mod.crafting.TargetNBTIngredient; -import de.ellpeck.actuallyadditions.mod.crafting.WrappedRecipe; import de.ellpeck.actuallyadditions.mod.items.ActuallyItems; -import net.minecraft.data.CachedOutput; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.data.PackOutput; -import net.minecraft.data.recipes.FinishedRecipe; import net.minecraft.data.recipes.RecipeCategory; +import net.minecraft.data.recipes.RecipeOutput; import net.minecraft.data.recipes.RecipeProvider; import net.minecraft.data.recipes.ShapedRecipeBuilder; import net.minecraft.data.recipes.ShapelessRecipeBuilder; @@ -22,17 +18,12 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.item.enchantment.Enchantments; import net.minecraft.world.level.ItemLike; -import net.minecraftforge.common.Tags; -import net.minecraftforge.common.crafting.ConditionalRecipe; -import net.minecraftforge.common.crafting.StrictNBTIngredient; -import net.minecraftforge.registries.ForgeRegistries; -import net.minecraftforge.registries.RegistryObject; -import org.jetbrains.annotations.Nullable; +import net.neoforged.neoforge.common.Tags; +import net.neoforged.neoforge.common.crafting.NBTIngredient; +import net.neoforged.neoforge.registries.DeferredItem; import javax.annotation.Nonnull; import java.util.Arrays; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; public class ItemRecipeGenerator extends RecipeProvider { public ItemRecipeGenerator(PackOutput packOutput) { @@ -45,7 +36,7 @@ public class ItemRecipeGenerator extends RecipeProvider { } @Override - protected void buildRecipes(Consumer consumer) { + protected void buildRecipes(RecipeOutput consumer) { generatePaxels(consumer); //Goggles @@ -156,7 +147,7 @@ public class ItemRecipeGenerator extends RecipeProvider { Recipe.shapeless(ActuallyItems.LENS_OF_THE_KILLER.get()) .requires(Items.DIAMOND_SWORD) .requires(ActuallyItems.LENS_OF_CERTAIN_DEATH.get()) - .requires(StrictNBTIngredient.of(enchantedBook)).save(consumer); + .requires(NBTIngredient.of(true, enchantedBook)).save(consumer); //Filter @@ -374,45 +365,45 @@ public class ItemRecipeGenerator extends RecipeProvider { .define('C', ActuallyItems.ADVANCED_COIL.get()) .save(consumer); - //Double Battery - Recipe.shaped(ActuallyItems.DOUBLE_BATTERY.get()) - .pattern(" R ") - .pattern("ICI") - .pattern("III") - .define('R', TargetNBTIngredient.of(ActuallyItems.SINGLE_BATTERY.get())) - .define('I', ActuallyItems.ENORI_CRYSTAL.get()) - .define('C', ActuallyItems.ADVANCED_COIL.get()) - .save(WrappedRecipe.Inject(consumer, ActuallyRecipes.KEEP_DATA_SHAPED_RECIPE.get())); - - //Triple Battery - Recipe.shaped(ActuallyItems.TRIPLE_BATTERY.get()) - .pattern(" R ") - .pattern("ICI") - .pattern("III") - .define('R', TargetNBTIngredient.of(ActuallyItems.DOUBLE_BATTERY.get())) - .define('I', ActuallyItems.EMPOWERED_ENORI_CRYSTAL.get()) - .define('C', ActuallyItems.ADVANCED_COIL.get()) - .save(WrappedRecipe.Inject(consumer, ActuallyRecipes.KEEP_DATA_SHAPED_RECIPE.get())); - - //Quad Battery - Recipe.shaped(ActuallyItems.QUADRUPLE_BATTERY.get()) - .pattern(" R ") - .pattern("ICI") - .pattern("III") - .define('R', TargetNBTIngredient.of(ActuallyItems.TRIPLE_BATTERY.get())) - .define('I', ActuallyItems.EMPOWERED_ENORI_CRYSTAL.get()) - .define('C', ActuallyItems.ADVANCED_COIL.get()) - .save(WrappedRecipe.Inject(consumer, ActuallyRecipes.KEEP_DATA_SHAPED_RECIPE.get())); - - //Quintuple Battery - Recipe.shaped(ActuallyItems.QUINTUPLE_BATTERY.get()) - .pattern(" R ") - .pattern("ICI") - .pattern("III") - .define('R', TargetNBTIngredient.of(ActuallyItems.QUADRUPLE_BATTERY.get())) - .define('I', ActuallyItems.EMPOWERED_DIAMATINE_CRYSTAL.get()) - .define('C', ActuallyItems.ADVANCED_COIL.get()) - .save(WrappedRecipe.Inject(consumer, ActuallyRecipes.KEEP_DATA_SHAPED_RECIPE.get())); +// //Double Battery TODO: Flanks please fix these :) +// Recipe.shaped(ActuallyItems.DOUBLE_BATTERY.get()) +// .pattern(" R ") +// .pattern("ICI") +// .pattern("III") +// .define('R', TargetNBTIngredient.of(ActuallyItems.SINGLE_BATTERY.get())) +// .define('I', ActuallyItems.ENORI_CRYSTAL.get()) +// .define('C', ActuallyItems.ADVANCED_COIL.get()) +// .save(WrappedRecipe.Inject(consumer, ActuallyRecipes.KEEP_DATA_SHAPED_RECIPE.get())); +// +// //Triple Battery +// Recipe.shaped(ActuallyItems.TRIPLE_BATTERY.get()) +// .pattern(" R ") +// .pattern("ICI") +// .pattern("III") +// .define('R', TargetNBTIngredient.of(ActuallyItems.DOUBLE_BATTERY.get())) +// .define('I', ActuallyItems.EMPOWERED_ENORI_CRYSTAL.get()) +// .define('C', ActuallyItems.ADVANCED_COIL.get()) +// .save(WrappedRecipe.Inject(consumer, ActuallyRecipes.KEEP_DATA_SHAPED_RECIPE.get())); +// +// //Quad Battery +// Recipe.shaped(ActuallyItems.QUADRUPLE_BATTERY.get()) +// .pattern(" R ") +// .pattern("ICI") +// .pattern("III") +// .define('R', TargetNBTIngredient.of(ActuallyItems.TRIPLE_BATTERY.get())) +// .define('I', ActuallyItems.EMPOWERED_ENORI_CRYSTAL.get()) +// .define('C', ActuallyItems.ADVANCED_COIL.get()) +// .save(WrappedRecipe.Inject(consumer, ActuallyRecipes.KEEP_DATA_SHAPED_RECIPE.get())); +// +// //Quintuple Battery +// Recipe.shaped(ActuallyItems.QUINTUPLE_BATTERY.get()) +// .pattern(" R ") +// .pattern("ICI") +// .pattern("III") +// .define('R', TargetNBTIngredient.of(ActuallyItems.QUADRUPLE_BATTERY.get())) +// .define('I', ActuallyItems.EMPOWERED_DIAMATINE_CRYSTAL.get()) +// .define('C', ActuallyItems.ADVANCED_COIL.get()) +// .save(WrappedRecipe.Inject(consumer, ActuallyRecipes.KEEP_DATA_SHAPED_RECIPE.get())); //Magnet Ring Recipe.shaped(ActuallyItems.RING_OF_MAGNETIZING.get()) @@ -433,31 +424,19 @@ public class ItemRecipeGenerator extends RecipeProvider { Recipe.shapeless(ActuallyItems.CRAFTER_ON_A_STICK.get()).requires(Items.CRAFTING_TABLE).requires(ItemTags.SIGNS).save(consumer); - ConditionalRecipe.builder() - .addCondition(new BoolConfigCondition("tinyCoalStuff")) - .addRecipe( - Recipe.shapeless(ActuallyItems.TINY_COAL.get(), 8) - .requires(Items.COAL)::save) - .generateAdvancement().build(consumer, new ResourceLocation(ActuallyAdditions.MODID, "coal_to_tiny")); - ConditionalRecipe.builder() - .addCondition(new BoolConfigCondition("tinyCoalStuff")) - .addRecipe( - Recipe.shapeless(ActuallyItems.TINY_CHARCOAL.get(), 8) - .requires(Items.CHARCOAL)::save) - .generateAdvancement().build(consumer, new ResourceLocation(ActuallyAdditions.MODID, "charcoal_to_tiny")); + RecipeOutput boolConsumer = consumer.withConditions(new BoolConfigCondition("tinyCoalStuff")); - ConditionalRecipe.builder() - .addCondition(new BoolConfigCondition("tinyCoalStuff")) - .addRecipe( - Recipe.shaped(Items.COAL) - .pattern("CCC", "C C", "CCC").define('C', ActuallyItems.TINY_COAL.get())::save) - .generateAdvancement().build(consumer, new ResourceLocation(ActuallyAdditions.MODID, "tiny_to_coal")); - ConditionalRecipe.builder() - .addCondition(new BoolConfigCondition("tinyCoalStuff")) - .addRecipe( - Recipe.shaped(Items.CHARCOAL) - .pattern("CCC", "C C", "CCC").define('C', ActuallyItems.TINY_CHARCOAL.get())::save) - .generateAdvancement().build(consumer, new ResourceLocation(ActuallyAdditions.MODID, "tiny_to_charcoal")); + Recipe.shapeless(ActuallyItems.TINY_COAL.get(), 8) + .requires(Items.COAL) + .save(boolConsumer, new ResourceLocation(ActuallyAdditions.MODID, "coal_to_tiny")); + Recipe.shapeless(ActuallyItems.TINY_CHARCOAL.get(), 8) + .requires(Items.CHARCOAL).save(boolConsumer, new ResourceLocation(ActuallyAdditions.MODID, "charcoal_to_tiny")); + Recipe.shaped(Items.COAL) + .pattern("CCC", "C C", "CCC").define('C', ActuallyItems.TINY_COAL.get()) + .save(boolConsumer, new ResourceLocation(ActuallyAdditions.MODID, "tiny_to_coal")); + Recipe.shaped(Items.CHARCOAL) + .pattern("CCC", "C C", "CCC").define('C', ActuallyItems.TINY_CHARCOAL.get()) + .save(boolConsumer, new ResourceLocation(ActuallyAdditions.MODID, "tiny_to_charcoal")); //Canola Seeds Recipe.shapeless(ActuallyItems.CANOLA_SEEDS.get()) @@ -516,7 +495,7 @@ public class ItemRecipeGenerator extends RecipeProvider { // GameRegistry.addSmelting(new ItemStack(InitItems.itemDust, 1, TheDusts.COAL.ordinal()), new ItemStack(Items.COAL), 1F); } - protected void generatePaxels(Consumer consumer) { + protected void generatePaxels(RecipeOutput consumer) { addPaxel(consumer, ActuallyItems.WOODEN_AIOT, Items.WOODEN_AXE, Items.WOODEN_PICKAXE, Items.WOODEN_SWORD, Items.WOODEN_SHOVEL, Items.WOODEN_HOE); addPaxel(consumer, ActuallyItems.STONE_AIOT, Items.STONE_AXE, Items.STONE_PICKAXE, Items.STONE_SWORD, Items.STONE_SHOVEL, Items.STONE_HOE); addPaxel(consumer, ActuallyItems.IRON_AIOT, Items.IRON_AXE, Items.IRON_PICKAXE, Items.IRON_SWORD, Items.IRON_SHOVEL, Items.IRON_HOE); @@ -525,7 +504,7 @@ public class ItemRecipeGenerator extends RecipeProvider { addPaxel(consumer, ActuallyItems.NETHERITE_AIOT, Items.NETHERITE_AXE, Items.NETHERITE_PICKAXE, Items.NETHERITE_SWORD, Items.NETHERITE_SHOVEL, Items.NETHERITE_HOE); } - public static void addPaxel(Consumer consumer, RegistryObject output, Item axe, Item pickaxe, Item sword, Item shovel, Item hoe) { + public static void addPaxel(RecipeOutput consumer, DeferredItem output, Item axe, Item pickaxe, Item sword, Item shovel, Item hoe) { Recipe.shapeless(output.get()) .requires(axe) .requires(pickaxe) @@ -535,7 +514,7 @@ public class ItemRecipeGenerator extends RecipeProvider { .save(consumer); } - public static void addPaxel(Consumer consumer, RegistryObject output, RegistryObject axe, RegistryObject pickaxe, RegistryObject sword, RegistryObject shovel, RegistryObject hoe) { + public static void addPaxel(RecipeOutput consumer, DeferredItem output, DeferredItem axe, DeferredItem pickaxe, DeferredItem sword, DeferredItem shovel, DeferredItem hoe) { Recipe.shapeless(output.get()) .requires(axe.get()) .requires(pickaxe.get()) @@ -545,25 +524,26 @@ public class ItemRecipeGenerator extends RecipeProvider { .save(consumer); } - public static void decompress(Consumer consumer, RegistryObject output, RegistryObject input) { - ResourceLocation key = ForgeRegistries.ITEMS.getKey(output.get()); + public static void decompress(RecipeOutput consumer, DeferredItem output, DeferredItem input) { + ResourceLocation key = BuiltInRegistries.ITEM.getKey(output.get()); Recipe.shapeless(output.get(), 9).requires(input.get()).save(consumer, new ResourceLocation(key.getNamespace(), "decompress/" + key.getPath())); } - public static void compress(Consumer consumer, RegistryObject output, RegistryObject input) { - ResourceLocation key = ForgeRegistries.ITEMS.getKey(output.get()); + public static void compress(RecipeOutput consumer, DeferredItem output, DeferredItem input) { + ResourceLocation key = BuiltInRegistries.ITEM.getKey(output.get()); Recipe.shaped(output.get()).pattern("xxx","xxx", "xxx").define('x', input.get()).save(consumer, new ResourceLocation(key.getNamespace(), "compress/" + key.getPath())); } - public static void addShard(Consumer consumer, RegistryObject shard, RegistryObject crystal) { + public static void addShard(RecipeOutput consumer, DeferredItem shard, DeferredItem crystal) { compress(consumer, crystal, shard); decompress(consumer, shard, crystal); } - @Override - protected @Nullable CompletableFuture saveAdvancement(CachedOutput output, FinishedRecipe finishedRecipe, JsonObject advancementJson) { - return null; //Nope... - } +// @Override //TODO: Flanks do your RecipeOutput wrapper thingy ;) +// protected @Nullable CompletableFuture saveAdvancement(CachedOutput stack, FinishedRecipe finishedRecipe, JsonObject advancementJson) { +// return null; +// //Nope... maybe later... +// } - public static void addToolAndArmorRecipes(Consumer consumer, RegistryObject base, RegistryObject pickaxe, RegistryObject sword, RegistryObject axe, RegistryObject shovel, RegistryObject hoe, RegistryObject helm, RegistryObject chest, RegistryObject pants, RegistryObject boots) { + public static void addToolAndArmorRecipes(RecipeOutput consumer, DeferredItem base, DeferredItem pickaxe, DeferredItem sword, DeferredItem axe, DeferredItem shovel, DeferredItem hoe, DeferredItem helm, DeferredItem chest, DeferredItem pants, DeferredItem boots) { //Pickaxe Recipe.shaped(pickaxe.get()) .pattern("EEE", " S ", " S ") @@ -662,7 +642,7 @@ public class ItemRecipeGenerator extends RecipeProvider { } @Override - public void save(@Nonnull Consumer consumer) { + public void save(@Nonnull RecipeOutput consumer) { this.unlockedBy("has_book", has(ActuallyItems.ITEM_BOOKLET.get())); if (this.name != null) { this.save(consumer, this.name); @@ -671,7 +651,7 @@ public class ItemRecipeGenerator extends RecipeProvider { } } @Override - public void save(@Nonnull Consumer consumer, @Nonnull ResourceLocation location) { + public void save(@Nonnull RecipeOutput consumer, @Nonnull ResourceLocation location) { this.unlockedBy("", has(Items.AIR)); super.save(consumer, location); } @@ -714,13 +694,13 @@ public class ItemRecipeGenerator extends RecipeProvider { } @Override - public void save(@Nonnull Consumer consumerIn) { + public void save(@Nonnull RecipeOutput consumerIn) { this.unlockedBy("has_book", has(ActuallyItems.ITEM_BOOKLET.get())); super.save(consumerIn); } @Override - public void save(@Nonnull Consumer consumer, @Nonnull ResourceLocation location) { + public void save(@Nonnull RecipeOutput consumer, @Nonnull ResourceLocation location) { this.unlockedBy("", has(Items.AIR)); super.save(consumer, location); } diff --git a/src/main/java/de/ellpeck/actuallyadditions/data/ItemTagsGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/data/ItemTagsGenerator.java index d4ea4a216..8ff59a227 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/data/ItemTagsGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/data/ItemTagsGenerator.java @@ -8,7 +8,7 @@ import net.minecraft.data.PackOutput; import net.minecraft.data.tags.ItemTagsProvider; import net.minecraft.data.tags.TagsProvider; import net.minecraft.world.level.block.Block; -import net.minecraftforge.common.data.ExistingFileHelper; +import net.neoforged.neoforge.common.data.ExistingFileHelper; import java.util.concurrent.CompletableFuture; diff --git a/src/main/java/de/ellpeck/actuallyadditions/data/LaserRecipeGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/data/LaserRecipeGenerator.java index 6265fbe17..575256556 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/data/LaserRecipeGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/data/LaserRecipeGenerator.java @@ -1,13 +1,12 @@ package de.ellpeck.actuallyadditions.data; -import com.google.gson.JsonObject; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks; import de.ellpeck.actuallyadditions.mod.crafting.LaserRecipe; import de.ellpeck.actuallyadditions.mod.items.ActuallyItems; -import net.minecraft.data.CachedOutput; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.data.PackOutput; -import net.minecraft.data.recipes.FinishedRecipe; +import net.minecraft.data.recipes.RecipeOutput; import net.minecraft.data.recipes.RecipeProvider; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.ItemTags; @@ -16,12 +15,7 @@ import net.minecraft.world.item.Item; import net.minecraft.world.item.Items; import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.level.ItemLike; -import net.minecraftforge.common.Tags; -import net.minecraftforge.registries.ForgeRegistries; -import org.jetbrains.annotations.Nullable; - -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; +import net.neoforged.neoforge.common.Tags; public class LaserRecipeGenerator extends RecipeProvider { public LaserRecipeGenerator(PackOutput packOutput) { @@ -33,13 +27,14 @@ public class LaserRecipeGenerator extends RecipeProvider { return "Laser " + super.getName(); } - @Override - protected @Nullable CompletableFuture saveAdvancement(CachedOutput output, FinishedRecipe finishedRecipe, JsonObject advancementJson) { - return null; //Nope... - } +// @Override //TODO: Flanks do your RecipeOutput wrapper thingy ;) +// protected @Nullable CompletableFuture saveAdvancement(CachedOutput stack, FinishedRecipe finishedRecipe, JsonObject advancementJson) { +// return null; +// //Nope... maybe later... +// } @Override - protected void buildRecipes(Consumer consumer) { + protected void buildRecipes(RecipeOutput consumer) { //Crystal Blocks laserCrystalizeRecipe(consumer, ActuallyBlocks.RESTONIA_CRYSTAL.getItem(), Tags.Items.STORAGE_BLOCKS_REDSTONE, 400); laserCrystalizeRecipe(consumer, ActuallyBlocks.PALIS_CRYSTAL.getItem(), Tags.Items.STORAGE_BLOCKS_LAPIS, 400); @@ -78,28 +73,28 @@ public class LaserRecipeGenerator extends RecipeProvider { } - private void laserRecipe(Consumer consumer, ItemLike output, Ingredient input, int energy) { - consumer.accept(new LaserRecipe.Result(new ResourceLocation(ActuallyAdditions.MODID, "laser/" + ForgeRegistries.ITEMS.getKey(output.asItem()).getPath()), - input, energy, output)); + private void laserRecipe(RecipeOutput consumer, ItemLike output, Ingredient input, int energy) { + ResourceLocation id = new ResourceLocation(ActuallyAdditions.MODID, "laser/" + BuiltInRegistries.ITEM.getKey(output.asItem()).getPath()); + consumer.accept(id, new LaserRecipe(output.asItem().getDefaultInstance(), input, energy), null); } - private void laserRecipe(Consumer consumer, ItemLike output, TagKey input, int energy) { - consumer.accept(new LaserRecipe.Result(new ResourceLocation(ActuallyAdditions.MODID, "laser/" + ForgeRegistries.ITEMS.getKey(output.asItem()).getPath()), - Ingredient.of(input), energy, output)); + private void laserRecipe(RecipeOutput consumer, ItemLike output, TagKey input, int energy) { + ResourceLocation id = new ResourceLocation(ActuallyAdditions.MODID, "laser/" + BuiltInRegistries.ITEM.getKey(output.asItem()).getPath()); + consumer.accept(id, new LaserRecipe(output.asItem().getDefaultInstance(), Ingredient.of(input), energy), null); } - private void laserRecipe(Consumer consumer, ItemLike output, ItemLike input, int energy) { - consumer.accept(new LaserRecipe.Result(new ResourceLocation(ActuallyAdditions.MODID, "laser/" + ForgeRegistries.ITEMS.getKey(output.asItem()).getPath()), - Ingredient.of(input), energy, output)); + private void laserRecipe(RecipeOutput consumer, ItemLike output, ItemLike input, int energy) { + ResourceLocation id = new ResourceLocation(ActuallyAdditions.MODID, "laser/" + BuiltInRegistries.ITEM.getKey(output.asItem()).getPath()); + consumer.accept(id, new LaserRecipe(output.asItem().getDefaultInstance(), Ingredient.of(input), energy), null);; } - private void laserCrystalizeRecipe(Consumer consumer, ItemLike output, Ingredient input, int energy) { - consumer.accept(new LaserRecipe.Result(new ResourceLocation(ActuallyAdditions.MODID, "laser/crystalize_" + ForgeRegistries.ITEMS.getKey(output.asItem()).getPath()), - input, energy, output)); + private void laserCrystalizeRecipe(RecipeOutput consumer, ItemLike output, Ingredient input, int energy) { + ResourceLocation id = new ResourceLocation(ActuallyAdditions.MODID, "laser/crystalize_" + BuiltInRegistries.ITEM.getKey(output.asItem()).getPath()); + consumer.accept(id, new LaserRecipe(output.asItem().getDefaultInstance(), input, energy), null); } - private void laserCrystalizeRecipe(Consumer consumer, ItemLike output, TagKey input, int energy) { - consumer.accept(new LaserRecipe.Result(new ResourceLocation(ActuallyAdditions.MODID, "laser/crystalize_" + ForgeRegistries.ITEMS.getKey(output.asItem()).getPath()), - Ingredient.of(input), energy, output)); + private void laserCrystalizeRecipe(RecipeOutput consumer, ItemLike output, TagKey input, int energy) { + ResourceLocation id = new ResourceLocation(ActuallyAdditions.MODID, "laser/crystalize_" + BuiltInRegistries.ITEM.getKey(output.asItem()).getPath()); + consumer.accept(id, new LaserRecipe(output.asItem().getDefaultInstance(), Ingredient.of(input), energy), null); } - private void laserCrystalizeRecipe(Consumer consumer, ItemLike output, ItemLike input, int energy) { - consumer.accept(new LaserRecipe.Result(new ResourceLocation(ActuallyAdditions.MODID, "laser/crystalize_" + ForgeRegistries.ITEMS.getKey(output.asItem()).getPath()), - Ingredient.of(input), energy, output)); + private void laserCrystalizeRecipe(RecipeOutput consumer, ItemLike output, ItemLike input, int energy) { + ResourceLocation id = new ResourceLocation(ActuallyAdditions.MODID, "laser/crystalize_" + BuiltInRegistries.ITEM.getKey(output.asItem()).getPath()); + consumer.accept(id, new LaserRecipe(output.asItem().getDefaultInstance(), Ingredient.of(input), energy), null); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/data/LootTableGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/data/LootTableGenerator.java index e445a6b71..55c81ef3f 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/data/LootTableGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/data/LootTableGenerator.java @@ -24,7 +24,7 @@ import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets; import net.minecraft.world.level.storage.loot.predicates.LootItemBlockStatePropertyCondition; import net.minecraft.world.level.storage.loot.providers.nbt.ContextNbtProvider; import net.minecraft.world.level.storage.loot.providers.number.ConstantValue; -import net.minecraftforge.registries.RegistryObject; +import net.neoforged.neoforge.registries.DeferredHolder; import javax.annotation.Nonnull; import java.util.List; @@ -236,7 +236,7 @@ public class LootTableGenerator extends LootTableProvider { InitFluids.EMPOWERED_OIL.getBlock() ); - return ActuallyBlocks.BLOCKS.getEntries().stream().map(RegistryObject::get).filter(e -> !ignoreForNow.contains(e)).collect(Collectors.toList()); + return ActuallyBlocks.BLOCKS.getEntries().stream().map(DeferredHolder::get).filter(e -> !ignoreForNow.contains(e)).collect(Collectors.toList()); } } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/data/MiningLensGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/data/MiningLensGenerator.java index 7aed2a5c8..685ca07f6 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/data/MiningLensGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/data/MiningLensGenerator.java @@ -1,11 +1,9 @@ package de.ellpeck.actuallyadditions.data; -import com.google.gson.JsonObject; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.crafting.MiningLensRecipe; -import net.minecraft.data.CachedOutput; import net.minecraft.data.PackOutput; -import net.minecraft.data.recipes.FinishedRecipe; +import net.minecraft.data.recipes.RecipeOutput; import net.minecraft.data.recipes.RecipeProvider; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.TagKey; @@ -13,11 +11,7 @@ import net.minecraft.world.item.Item; import net.minecraft.world.item.Items; import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.level.ItemLike; -import net.minecraftforge.common.Tags; -import org.jetbrains.annotations.Nullable; - -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; +import net.neoforged.neoforge.common.Tags; public class MiningLensGenerator extends RecipeProvider { public MiningLensGenerator(PackOutput packOutput) { @@ -29,41 +23,41 @@ public class MiningLensGenerator extends RecipeProvider { return "Mining Lens " + super.getName(); } - @Override - protected @Nullable CompletableFuture saveAdvancement(CachedOutput output, FinishedRecipe finishedRecipe, JsonObject advancementJson) { - return null; //Nope... - } +// @Override //TODO: Flanks do your RecipeOutput wrapper thingy ;) +// protected @Nullable CompletableFuture saveAdvancement(CachedOutput stack, FinishedRecipe finishedRecipe, JsonObject advancementJson) { +// return null; +// //Nope... maybe later... +// } @Override - protected void buildRecipes(Consumer consumer) { + protected void buildRecipes(RecipeOutput consumer) { buildMiningLens(consumer); } // private String getItemName(ItemLike item) { -// return ForgeRegistries.ITEMS.getKey(item.asItem()).getPath(); +// return BuiltInRegistries.ITEM.getKey(item.asItem()).getPath(); // } private ResourceLocation folderRecipe(String folder, String recipe) { return new ResourceLocation(ActuallyAdditions.MODID, folder + "/" + recipe); } - private void buildStoneOre(Consumer consumer, int weight, ItemLike output) { + private void buildStoneOre(RecipeOutput consumer, int weight, ItemLike output) { buildTagOre(consumer, Tags.Items.STONE, "stone", weight, output); } - private void buildNetherOre(Consumer consumer, int weight, ItemLike output) { + private void buildNetherOre(RecipeOutput consumer, int weight, ItemLike output) { buildTagOre(consumer, Tags.Items.NETHERRACK, "nether", weight, output); } - private void buildTagOre(Consumer consumer, TagKey tag, String prefix, int weight, ItemLike output) { - consumer.accept(new MiningLensRecipe.Result( - folderRecipe("mininglens", prefix + "_" + getItemName(output)), + private void buildTagOre(RecipeOutput consumer, TagKey tag, String prefix, int weight, ItemLike output) { + consumer.accept(folderRecipe("mininglens", prefix + "_" + getItemName(output)), new MiningLensRecipe( Ingredient.of(tag), weight, - output - )); + output.asItem().getDefaultInstance() + ), null); } - private void buildMiningLens(Consumer consumer) { + private void buildMiningLens(RecipeOutput consumer) { buildStoneOre(consumer, 5000, Items.COAL_ORE); buildStoneOre(consumer, 3000, Items.IRON_ORE); buildStoneOre(consumer, 500, Items.GOLD_ORE); diff --git a/src/main/java/de/ellpeck/actuallyadditions/data/MiscMachineRecipeGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/data/MiscMachineRecipeGenerator.java index 932fbcb33..9bc0db19a 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/data/MiscMachineRecipeGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/data/MiscMachineRecipeGenerator.java @@ -1,22 +1,16 @@ package de.ellpeck.actuallyadditions.data; -import com.google.gson.JsonObject; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.crafting.FermentingRecipe; import de.ellpeck.actuallyadditions.mod.crafting.PressingRecipe; import de.ellpeck.actuallyadditions.mod.fluids.InitFluids; import de.ellpeck.actuallyadditions.mod.items.ActuallyItems; -import net.minecraft.data.CachedOutput; import net.minecraft.data.PackOutput; -import net.minecraft.data.recipes.FinishedRecipe; +import net.minecraft.data.recipes.RecipeOutput; import net.minecraft.data.recipes.RecipeProvider; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.crafting.Ingredient; -import net.minecraftforge.fluids.FluidStack; -import org.jetbrains.annotations.Nullable; - -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; +import net.neoforged.neoforge.fluids.FluidStack; public class MiscMachineRecipeGenerator extends RecipeProvider { public MiscMachineRecipeGenerator(PackOutput packOutput) { @@ -28,22 +22,23 @@ public class MiscMachineRecipeGenerator extends RecipeProvider { return "Misc " + super.getName(); } - @Override - protected @Nullable CompletableFuture saveAdvancement(CachedOutput output, FinishedRecipe finishedRecipe, JsonObject advancementJson) { - return null; //Nope... - } +// @Override //TODO: Flanks do your RecipeOutput wrapper thingy ;) +// protected @Nullable CompletableFuture saveAdvancement(CachedOutput stack, FinishedRecipe finishedRecipe, JsonObject advancementJson) { +// return null; +// //Nope... maybe later... +// } @Override - protected void buildRecipes(Consumer consumer) { - consumer.accept(new PressingRecipe.Result(folderRecipe("pressing", "canola"), - Ingredient.of(ActuallyItems.CANOLA.get()), new FluidStack(InitFluids.CANOLA_OIL.get(), 80))); + protected void buildRecipes(RecipeOutput consumer) { + consumer.accept(folderRecipe("pressing", "canola"), new PressingRecipe( + Ingredient.of(ActuallyItems.CANOLA.get()), new FluidStack(InitFluids.CANOLA_OIL.get(), 80)), null); - consumer.accept(new FermentingRecipe.Result(folderRecipe("fermenting", "refined_canola"), - new FluidStack(InitFluids.CANOLA_OIL.get(), 80), new FluidStack(InitFluids.REFINED_CANOLA_OIL.get(), 80), 100)); + consumer.accept(folderRecipe("fermenting", "refined_canola"), new FermentingRecipe( + new FluidStack(InitFluids.CANOLA_OIL.get(), 80), new FluidStack(InitFluids.REFINED_CANOLA_OIL.get(), 80), 100), null); } // private String getItemName(ItemLike item) { -// return ForgeRegistries.ITEMS.getKey(item.asItem()).getPath(); +// return BuiltInRegistries.ITEM.getKey(item.asItem()).getPath(); // } private ResourceLocation folderRecipe(String folder, String recipe) { diff --git a/src/main/java/de/ellpeck/actuallyadditions/data/SoundsGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/data/SoundsGenerator.java index 99cdb69fe..b0b750031 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/data/SoundsGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/data/SoundsGenerator.java @@ -4,8 +4,8 @@ import de.ellpeck.actuallyadditions.mod.AASounds; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import net.minecraft.data.PackOutput; import net.minecraft.resources.ResourceLocation; -import net.minecraftforge.common.data.ExistingFileHelper; -import net.minecraftforge.common.data.SoundDefinitionsProvider; +import net.neoforged.neoforge.common.data.ExistingFileHelper; +import net.neoforged.neoforge.common.data.SoundDefinitionsProvider; public class SoundsGenerator extends SoundDefinitionsProvider { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/AASounds.java b/src/main/java/de/ellpeck/actuallyadditions/mod/AASounds.java index 730fb984b..e57da7c3e 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/AASounds.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/AASounds.java @@ -1,19 +1,19 @@ package de.ellpeck.actuallyadditions.mod; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundEvent; -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.DeferredHolder; +import net.neoforged.neoforge.registries.DeferredRegister; public class AASounds { - public static final DeferredRegister SOUNDS = DeferredRegister.create(ForgeRegistries.SOUND_EVENTS, ActuallyAdditions.MODID); + public static final DeferredRegister SOUNDS = DeferredRegister.create(BuiltInRegistries.SOUND_EVENT, ActuallyAdditions.MODID); - public static RegistryObject RECONSTRUCTOR = SOUNDS.register("reconstructor", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation(ActuallyAdditions.MODID, "reconstructor"))); - public static RegistryObject CRUSHER = SOUNDS.register("crusher", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation(ActuallyAdditions.MODID, "crusher"))); - public static RegistryObject COFFEE_MACHINE = SOUNDS.register("coffee_machine", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation(ActuallyAdditions.MODID, "coffee_machine"))); - public static RegistryObject DUH_DUH_DUH_DUUUH = SOUNDS.register("duh_duh_duh_duuuh", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation(ActuallyAdditions.MODID, "duh_duh_duh_duuuh"))); + public static DeferredHolder RECONSTRUCTOR = SOUNDS.register("reconstructor", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation(ActuallyAdditions.MODID, "reconstructor"))); + public static DeferredHolder CRUSHER = SOUNDS.register("crusher", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation(ActuallyAdditions.MODID, "crusher"))); + public static DeferredHolder COFFEE_MACHINE = SOUNDS.register("coffee_machine", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation(ActuallyAdditions.MODID, "coffee_machine"))); + public static DeferredHolder DUH_DUH_DUH_DUUUH = SOUNDS.register("duh_duh_duh_duuuh", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation(ActuallyAdditions.MODID, "duh_duh_duh_duuuh"))); public static void init(IEventBus bus) { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java b/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java index 1e9014a3f..527031eb5 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java @@ -10,6 +10,7 @@ package de.ellpeck.actuallyadditions.mod; +import com.mojang.serialization.Codec; import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; import de.ellpeck.actuallyadditions.api.ActuallyTags; import de.ellpeck.actuallyadditions.api.farmer.IFarmerBehavior; @@ -18,7 +19,6 @@ import de.ellpeck.actuallyadditions.mod.config.CommonConfig; import de.ellpeck.actuallyadditions.mod.config.conditions.BoolConfigCondition; import de.ellpeck.actuallyadditions.mod.crafting.ActuallyRecipes; import de.ellpeck.actuallyadditions.mod.crafting.CrusherCrafting; -import de.ellpeck.actuallyadditions.mod.crafting.TargetNBTIngredient; import de.ellpeck.actuallyadditions.mod.data.WorldData; import de.ellpeck.actuallyadditions.mod.entity.EntityWorm; import de.ellpeck.actuallyadditions.mod.entity.InitEntities; @@ -36,33 +36,34 @@ import de.ellpeck.actuallyadditions.mod.network.PacketHandler; import de.ellpeck.actuallyadditions.mod.particle.ActuallyParticles; import de.ellpeck.actuallyadditions.mod.update.UpdateChecker; import de.ellpeck.actuallyadditions.mod.util.ResourceReloader; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.MobCategory; import net.minecraft.world.item.Item; import net.minecraft.world.item.Items; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.client.event.RegisterParticleProvidersEvent; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.common.crafting.CraftingHelper; -import net.minecraftforge.event.AddReloadListenerEvent; -import net.minecraftforge.event.server.ServerStartedEvent; -import net.minecraftforge.event.server.ServerStoppedEvent; -import net.minecraftforge.eventbus.api.IEventBus; -import net.minecraftforge.fml.DistExecutor; -import net.minecraftforge.fml.ModLoadingContext; -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.FMLClientSetupEvent; -import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; -import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; -import net.minecraftforge.registries.DeferredRegister; -import net.minecraftforge.registries.ForgeRegistries; -import net.minecraftforge.registries.RegistryObject; +import net.neoforged.bus.api.IEventBus; +import net.neoforged.fml.ModLoadingContext; +import net.neoforged.fml.common.Mod; +import net.neoforged.fml.config.ModConfig; +import net.neoforged.fml.event.config.ModConfigEvent; +import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent; +import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent; +import net.neoforged.fml.loading.FMLEnvironment; +import net.neoforged.neoforge.client.event.RegisterParticleProvidersEvent; +import net.neoforged.neoforge.common.NeoForge; +import net.neoforged.neoforge.common.conditions.ICondition; +import net.neoforged.neoforge.event.AddReloadListenerEvent; +import net.neoforged.neoforge.event.server.ServerStartedEvent; +import net.neoforged.neoforge.event.server.ServerStoppedEvent; +import net.neoforged.neoforge.registries.DeferredHolder; +import net.neoforged.neoforge.registries.DeferredRegister; +import net.neoforged.neoforge.registries.NeoForgeRegistries; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import java.util.function.Supplier; + @Mod(ActuallyAdditions.MODID) public class ActuallyAdditions { @@ -78,16 +79,18 @@ public class ActuallyAdditions { public static final Logger LOGGER = LogManager.getLogger(NAME); - public static final DeferredRegister> ENTITIES = DeferredRegister.create(ForgeRegistries.ENTITY_TYPES, MODID); - public static final RegistryObject> ENTITY_WORM = ENTITIES.register("worm", () -> EntityType.Builder.of(EntityWorm::new, MobCategory.MISC).build(MODID + ":worm")); + private static final DeferredRegister> ENTITIES = DeferredRegister.create(BuiltInRegistries.ENTITY_TYPE, MODID); + public static final Supplier> ENTITY_WORM = ENTITIES.register("worm", () -> EntityType.Builder.of(EntityWorm::new, MobCategory.MISC).build(MODID + ":worm")); + + private static final DeferredRegister> CONDITION_CODECS = DeferredRegister.create(NeoForgeRegistries.Keys.CONDITION_CODECS, MODID); + public static final DeferredHolder, Codec> BOOL_CONFIG_CONDITION = CONDITION_CODECS.register("bool_config_condition", () -> BoolConfigCondition.CODEC); + public static boolean commonCapsLoaded; - public ActuallyAdditions() { + public ActuallyAdditions(IEventBus eventBus) { ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, CommonConfig.COMMON_CONFIG); - IEventBus eventBus = FMLJavaModLoadingContext.get().getModEventBus(); - ActuallyBlocks.init(eventBus); ActuallyItems.init(eventBus); ActuallyTabs.init(eventBus); @@ -95,25 +98,27 @@ public class ActuallyAdditions { AASounds.init(eventBus); ActuallyContainers.CONTAINERS.register(eventBus); ENTITIES.register(eventBus); + CONDITION_CODECS.register(eventBus); eventBus.addListener(this::onConfigReload); ActuallyParticles.init(eventBus); ActuallyTags.init(); - MinecraftForge.EVENT_BUS.addListener(this::serverStarted); - MinecraftForge.EVENT_BUS.addListener(this::serverStopped); - MinecraftForge.EVENT_BUS.register(new CommonEvents()); - MinecraftForge.EVENT_BUS.register(new DungeonLoot()); - MinecraftForge.EVENT_BUS.addListener(ActuallyAdditions::reloadEvent); - MinecraftForge.EVENT_BUS.addListener(Worm::onHoe); + NeoForge.EVENT_BUS.addListener(this::serverStarted); + NeoForge.EVENT_BUS.addListener(this::serverStopped); + NeoForge.EVENT_BUS.register(new CommonEvents()); + NeoForge.EVENT_BUS.register(new DungeonLoot()); + NeoForge.EVENT_BUS.addListener(ActuallyAdditions::reloadEvent); + NeoForge.EVENT_BUS.addListener(Worm::onHoe); InitFluids.init(eventBus); + eventBus.addListener(PacketHandler::register); eventBus.addListener(this::setup); - DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> { - eventBus.addListener(this::clientSetup); - eventBus.addListener(ActuallyAdditionsClient::setupSpecialRenders); - eventBus.addListener(this::particleFactoryRegister); - }); + if (FMLEnvironment.dist.isClient()) { + eventBus.addListener(this::clientSetup); + eventBus.addListener(ActuallyAdditionsClient::setupSpecialRenders); + eventBus.addListener(this::particleFactoryRegister); + } IFarmerBehavior.initBehaviors(); } @@ -122,17 +127,11 @@ public class ActuallyAdditions { } private void setup(FMLCommonSetupEvent event) { - PacketHandler.init(); - - event.enqueueWork(() -> { - CraftingHelper.register(BoolConfigCondition.Serializer.INSTANCE); - }); - ActuallyAdditionsAPI.methodHandler = new MethodHandler(); ActuallyAdditionsAPI.connectionHandler = new LaserRelayConnectionHandler(); //Lenses.init(); // CompatUtil.registerCraftingTweaks(); - event.enqueueWork(() -> CraftingHelper.register(TargetNBTIngredient.Serializer.NAME, TargetNBTIngredient.SERIALIZER)); +// event.enqueueWork(() -> CraftingHelper.register(TargetNBTIngredient.Serializer.NAME, TargetNBTIngredient.SERIALIZER)); TODO: Flanks fix the Target NBT ingredient! commonCapsLoaded = false; // Loader.isModLoaded("commoncapabilities"); @@ -146,8 +145,8 @@ public class ActuallyAdditions { } private void onConfigReload(ModConfigEvent event) { - Item item1 = ForgeRegistries.ITEMS.getValue(new ResourceLocation(CommonConfig.Other.REDSTONECONFIGURATOR.get())); - Item item2 = ForgeRegistries.ITEMS.getValue(new ResourceLocation(CommonConfig.Other.RELAYCONFIGURATOR.get())); + Item item1 = BuiltInRegistries.ITEM.get(new ResourceLocation(CommonConfig.Other.REDSTONECONFIGURATOR.get())); + Item item2 = BuiltInRegistries.ITEM.get(new ResourceLocation(CommonConfig.Other.RELAYCONFIGURATOR.get())); CommonConfig.Other.redstoneConfigureItem = item1 != null?item1: Items.AIR; CommonConfig.Other.relayConfigureItem = item2 != null?item2: Items.AIR; } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditionsClient.java b/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditionsClient.java index ac36911f3..7c0390445 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditionsClient.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditionsClient.java @@ -60,9 +60,9 @@ import net.minecraft.core.BlockPos; import net.minecraft.network.protocol.game.ServerboundPlayerActionPacket; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.phys.BlockHitResult; -import net.minecraftforge.client.event.EntityRenderersEvent; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; +import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent; +import net.neoforged.neoforge.client.event.EntityRenderersEvent; +import net.neoforged.neoforge.common.NeoForge; public class ActuallyAdditionsClient { @@ -93,9 +93,9 @@ public class ActuallyAdditionsClient { MenuScreens.register(ActuallyContainers.RANGED_COLLECTOR_CONTAINER.get(), GuiRangedCollector::new); MenuScreens.register(ActuallyContainers.XPSOLIDIFIER_CONTAINER.get(), GuiXPSolidifier::new); // From old proxy - MinecraftForge.EVENT_BUS.register(new ClientEvents()); - MinecraftForge.EVENT_BUS.register(new ClientRegistryHandler()); - MinecraftForge.EVENT_BUS.register(new SpecialRenderInit()); + NeoForge.EVENT_BUS.register(new ClientEvents()); + NeoForge.EVENT_BUS.register(new ClientRegistryHandler()); + NeoForge.EVENT_BUS.register(new SpecialRenderInit()); event.enqueueWork(() -> ItemProperties.register(ActuallyItems.WORM.get(), new ResourceLocation(ActuallyAdditions.MODID, "snail"), diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyTabs.java b/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyTabs.java index a55fe9b43..0435d3e2b 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyTabs.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyTabs.java @@ -7,8 +7,8 @@ import net.minecraft.network.chat.Component; import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.CreativeModeTabs; import net.minecraft.world.item.ItemStack; -import net.minecraftforge.eventbus.api.IEventBus; -import net.minecraftforge.registries.DeferredRegister; +import net.neoforged.bus.api.IEventBus; +import net.neoforged.neoforge.registries.DeferredRegister; import java.util.List; import java.util.function.Supplier; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/ClientRegistryHandler.java b/src/main/java/de/ellpeck/actuallyadditions/mod/ClientRegistryHandler.java index ecb790eb8..a045ca688 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/ClientRegistryHandler.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/ClientRegistryHandler.java @@ -3,9 +3,9 @@ package de.ellpeck.actuallyadditions.mod; import net.minecraft.client.resources.model.ModelResourceLocation; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.material.Fluid; -import net.minecraftforge.client.event.ModelEvent.BakingCompleted; -import net.minecraftforge.client.event.ModelEvent.RegisterGeometryLoaders; -import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.neoforge.client.event.ModelEvent.BakingCompleted; +import net.neoforged.neoforge.client.event.ModelEvent.RegisterGeometryLoaders; import java.util.HashMap; import java.util.Map; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/ActuallyBlocks.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/ActuallyBlocks.java index 10b84d788..c1d8029b8 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/ActuallyBlocks.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/ActuallyBlocks.java @@ -13,6 +13,7 @@ package de.ellpeck.actuallyadditions.mod.blocks; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.blocks.base.AACrops; import de.ellpeck.actuallyadditions.mod.items.ActuallyItems; +import de.ellpeck.actuallyadditions.mod.items.base.ItemEnergy; import de.ellpeck.actuallyadditions.mod.items.metalists.Crystals; import de.ellpeck.actuallyadditions.mod.tile.TileEntityAtomicReconstructor; import de.ellpeck.actuallyadditions.mod.tile.TileEntityBatteryBox; @@ -62,6 +63,7 @@ import de.ellpeck.actuallyadditions.mod.tile.TileEntityShockSuppressor; import de.ellpeck.actuallyadditions.mod.tile.TileEntityVerticalDigger; import de.ellpeck.actuallyadditions.mod.tile.TileEntityXPSolidifier; import de.ellpeck.actuallyadditions.registration.AABlockReg; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.world.item.Item; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; @@ -73,19 +75,20 @@ import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.material.MapColor; import net.minecraft.world.level.material.PushReaction; -import net.minecraftforge.eventbus.api.IEventBus; -import net.minecraftforge.registries.DeferredRegister; -import net.minecraftforge.registries.ForgeRegistries; +import net.neoforged.bus.api.IEventBus; +import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent; +import net.neoforged.neoforge.registries.DeferredHolder; +import net.neoforged.neoforge.registries.DeferredRegister; import java.util.function.Supplier; public final class ActuallyBlocks { - public static final DeferredRegister BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, ActuallyAdditions.MODID); - public static final DeferredRegister> TILES = DeferredRegister.create(ForgeRegistries.BLOCK_ENTITY_TYPES, ActuallyAdditions.MODID); + public static final DeferredRegister.Blocks BLOCKS = DeferredRegister.createBlocks(ActuallyAdditions.MODID); + public static final DeferredRegister> TILES = DeferredRegister.create(BuiltInRegistries.BLOCK_ENTITY_TYPE, ActuallyAdditions.MODID); public static final Item.Properties defaultBlockItemProperties = new Item.Properties().stacksTo(64); - public static final BlockBehaviour.Properties miscBlockProperties = BlockBehaviour.Properties.copy(Blocks.STONE).requiresCorrectToolForDrops().strength(1.5f, 10f); + public static final BlockBehaviour.Properties miscBlockProperties = BlockBehaviour.Properties.ofFullCopy(Blocks.STONE).requiresCorrectToolForDrops().strength(1.5f, 10f); // Casings public static final AABlockReg WOOD_CASING = new AABlockReg<>("wood_casing", () -> new ActuallyBlock(miscBlockProperties), ActuallyBlock::createBlockItem); @@ -274,32 +277,32 @@ public final class ActuallyBlocks { public static final AABlockReg BLACK_QUARTZ_BRICK = new AABlockReg<>("black_quartz_brick_block", () -> new ActuallyBlock(miscBlockProperties), (b) -> new AABlockItem(b, defaultBlockItemProperties)); //Walls - public static final AABlockReg ETHETIC_GREEN_WALL = new AABlockReg<>("ethetic_green_wall", () -> new WallBlock(BlockBehaviour.Properties.copy(ETHETIC_GREEN_BLOCK.get())), (b) -> new AABlockItem(b, defaultBlockItemProperties)); - public static final AABlockReg ETHETIC_WHITE_WALL = new AABlockReg<>("ethetic_white_wall", () -> new WallBlock(BlockBehaviour.Properties.copy(ETHETIC_WHITE_BLOCK.get())), (b) -> new AABlockItem(b, defaultBlockItemProperties)); - public static final AABlockReg BLACK_QUARTZ_WALL = new AABlockReg<>("black_quartz_wall", () -> new WallBlock(BlockBehaviour.Properties.copy(BLACK_QUARTZ.get())), (b) -> new AABlockItem(b, defaultBlockItemProperties)); - public static final AABlockReg CHISELED_BLACK_QUARTZ_WALL = new AABlockReg<>("chiseled_black_quartz_wall", () -> new WallBlock(BlockBehaviour.Properties.copy(CHISELED_BLACK_QUARTZ.get())), (b) -> new AABlockItem(b, defaultBlockItemProperties)); - public static final AABlockReg SMOOTH_BLACK_QUARTZ_WALL = new AABlockReg<>("smooth_black_quartz_wall", () -> new WallBlock(BlockBehaviour.Properties.copy(CHISELED_BLACK_QUARTZ.get())), (b) -> new AABlockItem(b, defaultBlockItemProperties)); - public static final AABlockReg BLACK_QUARTZ_BRICK_WALL = new AABlockReg<>("black_quartz_brick_wall", () -> new WallBlock(BlockBehaviour.Properties.copy(CHISELED_BLACK_QUARTZ.get())), (b) -> new AABlockItem(b, defaultBlockItemProperties)); - public static final AABlockReg BLACK_QUARTZ_PILLAR_WALL = new AABlockReg<>("black_quartz_pillar_wall", () -> new WallBlock(BlockBehaviour.Properties.copy(BLACK_QUARTZ_PILLAR.get())), (b) -> new AABlockItem(b, defaultBlockItemProperties)); + public static final AABlockReg ETHETIC_GREEN_WALL = new AABlockReg<>("ethetic_green_wall", () -> new WallBlock(BlockBehaviour.Properties.ofFullCopy(ETHETIC_GREEN_BLOCK.get())), (b) -> new AABlockItem(b, defaultBlockItemProperties)); + public static final AABlockReg ETHETIC_WHITE_WALL = new AABlockReg<>("ethetic_white_wall", () -> new WallBlock(BlockBehaviour.Properties.ofFullCopy(ETHETIC_WHITE_BLOCK.get())), (b) -> new AABlockItem(b, defaultBlockItemProperties)); + public static final AABlockReg BLACK_QUARTZ_WALL = new AABlockReg<>("black_quartz_wall", () -> new WallBlock(BlockBehaviour.Properties.ofFullCopy(BLACK_QUARTZ.get())), (b) -> new AABlockItem(b, defaultBlockItemProperties)); + public static final AABlockReg CHISELED_BLACK_QUARTZ_WALL = new AABlockReg<>("chiseled_black_quartz_wall", () -> new WallBlock(BlockBehaviour.Properties.ofFullCopy(CHISELED_BLACK_QUARTZ.get())), (b) -> new AABlockItem(b, defaultBlockItemProperties)); + public static final AABlockReg SMOOTH_BLACK_QUARTZ_WALL = new AABlockReg<>("smooth_black_quartz_wall", () -> new WallBlock(BlockBehaviour.Properties.ofFullCopy(CHISELED_BLACK_QUARTZ.get())), (b) -> new AABlockItem(b, defaultBlockItemProperties)); + public static final AABlockReg BLACK_QUARTZ_BRICK_WALL = new AABlockReg<>("black_quartz_brick_wall", () -> new WallBlock(BlockBehaviour.Properties.ofFullCopy(CHISELED_BLACK_QUARTZ.get())), (b) -> new AABlockItem(b, defaultBlockItemProperties)); + public static final AABlockReg BLACK_QUARTZ_PILLAR_WALL = new AABlockReg<>("black_quartz_pillar_wall", () -> new WallBlock(BlockBehaviour.Properties.ofFullCopy(BLACK_QUARTZ_PILLAR.get())), (b) -> new AABlockItem(b, defaultBlockItemProperties)); //Slabs - public static final AABlockReg ETHETIC_GREEN_SLAB = new AABlockReg<>("ethetic_green_slab", () -> new SlabBlock(BlockBehaviour.Properties.copy(ETHETIC_GREEN_BLOCK.get())), (b) -> new AABlockItem(b, defaultBlockItemProperties)); - public static final AABlockReg ETHETIC_WHITE_SLAB = new AABlockReg<>("ethetic_white_slab", () -> new SlabBlock(BlockBehaviour.Properties.copy(ETHETIC_WHITE_BLOCK.get())), (b) -> new AABlockItem(b, defaultBlockItemProperties)); - public static final AABlockReg BLACK_QUARTZ_SLAB = new AABlockReg<>("black_quartz_slab", () -> new SlabBlock(BlockBehaviour.Properties.copy(BLACK_QUARTZ.get())), (b) -> new AABlockItem(b, defaultBlockItemProperties)); - public static final AABlockReg CHISELED_BLACK_QUARTZ_SLAB = new AABlockReg<>("chiseled_black_quartz_slab", () -> new SlabBlock(BlockBehaviour.Properties.copy(CHISELED_BLACK_QUARTZ.get())), (b) -> new AABlockItem(b, defaultBlockItemProperties)); - public static final AABlockReg BLACK_QUARTZ_PILLAR_SLAB = new AABlockReg<>("black_quartz_pillar_slab", () -> new SlabBlock(BlockBehaviour.Properties.copy(BLACK_QUARTZ_PILLAR.get())), (b) -> new AABlockItem(b, defaultBlockItemProperties)); - public static final AABlockReg SMOOTH_BLACK_QUARTZ_SLAB = new AABlockReg<>("smooth_black_quartz_slab", () -> new SlabBlock(BlockBehaviour.Properties.copy(BLACK_QUARTZ_PILLAR.get())), (b) -> new AABlockItem(b, defaultBlockItemProperties)); - public static final AABlockReg BLACK_QUARTZ_BRICK_SLAB = new AABlockReg<>("black_quartz_brick_slab", () -> new SlabBlock(BlockBehaviour.Properties.copy(BLACK_QUARTZ_PILLAR.get())), (b) -> new AABlockItem(b, defaultBlockItemProperties)); + public static final AABlockReg ETHETIC_GREEN_SLAB = new AABlockReg<>("ethetic_green_slab", () -> new SlabBlock(BlockBehaviour.Properties.ofFullCopy(ETHETIC_GREEN_BLOCK.get())), (b) -> new AABlockItem(b, defaultBlockItemProperties)); + public static final AABlockReg ETHETIC_WHITE_SLAB = new AABlockReg<>("ethetic_white_slab", () -> new SlabBlock(BlockBehaviour.Properties.ofFullCopy(ETHETIC_WHITE_BLOCK.get())), (b) -> new AABlockItem(b, defaultBlockItemProperties)); + public static final AABlockReg BLACK_QUARTZ_SLAB = new AABlockReg<>("black_quartz_slab", () -> new SlabBlock(BlockBehaviour.Properties.ofFullCopy(BLACK_QUARTZ.get())), (b) -> new AABlockItem(b, defaultBlockItemProperties)); + public static final AABlockReg CHISELED_BLACK_QUARTZ_SLAB = new AABlockReg<>("chiseled_black_quartz_slab", () -> new SlabBlock(BlockBehaviour.Properties.ofFullCopy(CHISELED_BLACK_QUARTZ.get())), (b) -> new AABlockItem(b, defaultBlockItemProperties)); + public static final AABlockReg BLACK_QUARTZ_PILLAR_SLAB = new AABlockReg<>("black_quartz_pillar_slab", () -> new SlabBlock(BlockBehaviour.Properties.ofFullCopy(BLACK_QUARTZ_PILLAR.get())), (b) -> new AABlockItem(b, defaultBlockItemProperties)); + public static final AABlockReg SMOOTH_BLACK_QUARTZ_SLAB = new AABlockReg<>("smooth_black_quartz_slab", () -> new SlabBlock(BlockBehaviour.Properties.ofFullCopy(BLACK_QUARTZ_PILLAR.get())), (b) -> new AABlockItem(b, defaultBlockItemProperties)); + public static final AABlockReg BLACK_QUARTZ_BRICK_SLAB = new AABlockReg<>("black_quartz_brick_slab", () -> new SlabBlock(BlockBehaviour.Properties.ofFullCopy(BLACK_QUARTZ_PILLAR.get())), (b) -> new AABlockItem(b, defaultBlockItemProperties)); //Stairs - public static final AABlockReg ETHETIC_GREEN_STAIRS = new AABlockReg<>("ethetic_green_stairs", () -> new StairBlock(() -> ETHETIC_GREEN_BLOCK.get().defaultBlockState(), BlockBehaviour.Properties.copy(ETHETIC_GREEN_BLOCK.get())), (b) -> new AABlockItem(b, defaultBlockItemProperties)); - public static final AABlockReg ETHETIC_WHITE_STAIRS = new AABlockReg<>("ethetic_white_stairs", () -> new StairBlock(() -> ETHETIC_WHITE_BLOCK.get().defaultBlockState(), BlockBehaviour.Properties.copy(ETHETIC_WHITE_BLOCK.get())), (b) -> new AABlockItem(b, defaultBlockItemProperties)); - public static final AABlockReg BLACK_QUARTZ_STAIR = new AABlockReg<>("black_quartz_stair", () -> new StairBlock(() -> BLACK_QUARTZ.get().defaultBlockState(), BlockBehaviour.Properties.copy(BLACK_QUARTZ.get())), (b) -> new AABlockItem(b, defaultBlockItemProperties)); - public static final AABlockReg CHISELED_BLACK_QUARTZ_STAIR = new AABlockReg<>("chiseled_black_quartz_stair", () -> new StairBlock(() -> CHISELED_BLACK_QUARTZ.get().defaultBlockState(), BlockBehaviour.Properties.copy(CHISELED_BLACK_QUARTZ.get())), (b) -> new AABlockItem(b, defaultBlockItemProperties)); - public static final AABlockReg BLACK_QUARTZ_PILLAR_STAIR = new AABlockReg<>("black_quartz_pillar_stair", () -> new StairBlock(() -> BLACK_QUARTZ_PILLAR.get().defaultBlockState(), BlockBehaviour.Properties.copy(BLACK_QUARTZ_PILLAR.get())), (b) -> new AABlockItem(b, defaultBlockItemProperties)); - public static final AABlockReg SMOOTH_BLACK_QUARTZ_STAIR = new AABlockReg<>("smooth_black_quartz_stair", () -> new StairBlock(() -> BLACK_QUARTZ_PILLAR.get().defaultBlockState(), BlockBehaviour.Properties.copy(BLACK_QUARTZ_PILLAR.get())), (b) -> new AABlockItem(b, defaultBlockItemProperties)); - public static final AABlockReg BLACK_QUARTZ_BRICK_STAIR = new AABlockReg<>("black_quartz_brick_stair", () -> new StairBlock(() -> BLACK_QUARTZ_PILLAR.get().defaultBlockState(), BlockBehaviour.Properties.copy(BLACK_QUARTZ_PILLAR.get())), (b) -> new AABlockItem(b, defaultBlockItemProperties)); + public static final AABlockReg ETHETIC_GREEN_STAIRS = new AABlockReg<>("ethetic_green_stairs", () -> new StairBlock(() -> ETHETIC_GREEN_BLOCK.get().defaultBlockState(), BlockBehaviour.Properties.ofFullCopy(ETHETIC_GREEN_BLOCK.get())), (b) -> new AABlockItem(b, defaultBlockItemProperties)); + public static final AABlockReg ETHETIC_WHITE_STAIRS = new AABlockReg<>("ethetic_white_stairs", () -> new StairBlock(() -> ETHETIC_WHITE_BLOCK.get().defaultBlockState(), BlockBehaviour.Properties.ofFullCopy(ETHETIC_WHITE_BLOCK.get())), (b) -> new AABlockItem(b, defaultBlockItemProperties)); + public static final AABlockReg BLACK_QUARTZ_STAIR = new AABlockReg<>("black_quartz_stair", () -> new StairBlock(() -> BLACK_QUARTZ.get().defaultBlockState(), BlockBehaviour.Properties.ofFullCopy(BLACK_QUARTZ.get())), (b) -> new AABlockItem(b, defaultBlockItemProperties)); + public static final AABlockReg CHISELED_BLACK_QUARTZ_STAIR = new AABlockReg<>("chiseled_black_quartz_stair", () -> new StairBlock(() -> CHISELED_BLACK_QUARTZ.get().defaultBlockState(), BlockBehaviour.Properties.ofFullCopy(CHISELED_BLACK_QUARTZ.get())), (b) -> new AABlockItem(b, defaultBlockItemProperties)); + public static final AABlockReg BLACK_QUARTZ_PILLAR_STAIR = new AABlockReg<>("black_quartz_pillar_stair", () -> new StairBlock(() -> BLACK_QUARTZ_PILLAR.get().defaultBlockState(), BlockBehaviour.Properties.ofFullCopy(BLACK_QUARTZ_PILLAR.get())), (b) -> new AABlockItem(b, defaultBlockItemProperties)); + public static final AABlockReg SMOOTH_BLACK_QUARTZ_STAIR = new AABlockReg<>("smooth_black_quartz_stair", () -> new StairBlock(() -> BLACK_QUARTZ_PILLAR.get().defaultBlockState(), BlockBehaviour.Properties.ofFullCopy(BLACK_QUARTZ_PILLAR.get())), (b) -> new AABlockItem(b, defaultBlockItemProperties)); + public static final AABlockReg BLACK_QUARTZ_BRICK_STAIR = new AABlockReg<>("black_quartz_brick_stair", () -> new StairBlock(() -> BLACK_QUARTZ_PILLAR.get().defaultBlockState(), BlockBehaviour.Properties.ofFullCopy(BLACK_QUARTZ_PILLAR.get())), (b) -> new AABlockItem(b, defaultBlockItemProperties)); @@ -318,11 +321,11 @@ public final class ActuallyBlocks { (b) -> new AABlockItem(b, defaultBlockItemProperties)); public static BlockBehaviour.Properties defaultPickProps(float hardness, float resistance) { - return BlockBehaviour.Properties.copy(Blocks.STONE).requiresCorrectToolForDrops().strength(hardness, resistance).sound(SoundType.STONE); + return BlockBehaviour.Properties.ofFullCopy(Blocks.STONE).requiresCorrectToolForDrops().strength(hardness, resistance).sound(SoundType.STONE); } public static BlockBehaviour.Properties defaultPickProps() { - return BlockBehaviour.Properties.copy(Blocks.STONE).requiresCorrectToolForDrops().strength(1.5F, 10.0F).sound(SoundType.STONE); + return BlockBehaviour.Properties.ofFullCopy(Blocks.STONE).requiresCorrectToolForDrops().strength(1.5F, 10.0F).sound(SoundType.STONE); } public static BlockBehaviour.Properties defaultCropProps() { @@ -332,5 +335,10 @@ public final class ActuallyBlocks { public static void init(IEventBus evt) { BLOCKS.register(evt); TILES.register(evt); + evt.addListener(ActuallyBlocks::registerCapabilities); + } + + public static void registerCapabilities(RegisterCapabilitiesEvent event) { + //TODO: Register caps to the BlockEntities that have them } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockAtomicReconstructor.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockAtomicReconstructor.java index df2c55733..42a6ac420 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockAtomicReconstructor.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockAtomicReconstructor.java @@ -39,8 +39,8 @@ import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.level.block.state.properties.DirectionProperty; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.HitResult; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import javax.annotation.Nonnull; import javax.annotation.Nullable; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockCanolaPress.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockCanolaPress.java index a3f93a854..3bd50b1ff 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockCanolaPress.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockCanolaPress.java @@ -13,7 +13,6 @@ package de.ellpeck.actuallyadditions.mod.blocks; import de.ellpeck.actuallyadditions.mod.blocks.base.BlockContainerBase; import de.ellpeck.actuallyadditions.mod.tile.TileEntityCanolaPress; 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; @@ -26,8 +25,7 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; -import net.minecraftforge.fluids.FluidUtil; -import net.minecraftforge.network.NetworkHooks; +import net.neoforged.neoforge.fluids.FluidUtil; import javax.annotation.Nullable; @@ -63,7 +61,7 @@ public class BlockCanolaPress extends BlockContainerBase { return InteractionResult.SUCCESS; if (!player.isShiftKeyDown()) { if (!FluidUtil.interactWithFluidHandler(player, hand, tile.tank)) - NetworkHooks.openScreen((ServerPlayer) player, tile, pos); + player.openMenu(tile, pos); return InteractionResult.SUCCESS; } return InteractionResult.PASS; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockCoffeeMachine.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockCoffeeMachine.java index 9e4eee42f..622f24b00 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockCoffeeMachine.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockCoffeeMachine.java @@ -13,7 +13,6 @@ package de.ellpeck.actuallyadditions.mod.blocks; import de.ellpeck.actuallyadditions.mod.blocks.base.DirectionalBlock; import de.ellpeck.actuallyadditions.mod.tile.TileEntityCoffeeMachine; 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; @@ -26,7 +25,6 @@ import net.minecraft.world.level.block.state.BlockState; 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; @@ -41,7 +39,7 @@ public class BlockCoffeeMachine extends DirectionalBlock.Container { TileEntityCoffeeMachine tile = (TileEntityCoffeeMachine) world.getBlockEntity(pos); if (tile != null) { if (!this.tryUseItemOnTank(player, hand, tile.tank)) { - NetworkHooks.openScreen((ServerPlayer) player, tile, pos); + player.openMenu(tile, pos); } } return InteractionResult.PASS; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockFermentingBarrel.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockFermentingBarrel.java index 09f372b70..76bbef17c 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockFermentingBarrel.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockFermentingBarrel.java @@ -13,7 +13,6 @@ package de.ellpeck.actuallyadditions.mod.blocks; import de.ellpeck.actuallyadditions.mod.blocks.base.BlockContainerBase; import de.ellpeck.actuallyadditions.mod.tile.TileEntityFermentingBarrel; import net.minecraft.core.BlockPos; -import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundSource; import net.minecraft.world.InteractionHand; @@ -33,8 +32,7 @@ import net.minecraft.world.level.material.MapColor; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; -import net.minecraftforge.fluids.FluidUtil; -import net.minecraftforge.network.NetworkHooks; +import net.neoforged.neoforge.fluids.FluidUtil; import javax.annotation.Nullable; @@ -68,7 +66,7 @@ public class BlockFermentingBarrel extends BlockContainerBase { ItemStack stack = player.getItemInHand(hand); world.playSound(null, pos, stack.getItem() == Items.BUCKET ? SoundEvents.BUCKET_EMPTY:SoundEvents.BUCKET_FILL, SoundSource.BLOCKS, 1.0F, 1.0F); } else - NetworkHooks.openScreen((ServerPlayer) player, tile, pos); + player.openMenu(tile, pos); return InteractionResult.SUCCESS; } return InteractionResult.PASS; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockFluidCollector.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockFluidCollector.java index dcb613740..b063bbb2c 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockFluidCollector.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockFluidCollector.java @@ -26,7 +26,7 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; -import net.minecraftforge.fluids.FluidUtil; +import net.neoforged.neoforge.fluids.FluidUtil; import javax.annotation.Nonnull; import javax.annotation.Nullable; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockLaserRelay.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockLaserRelay.java index 6dafbd937..16a19fc89 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockLaserRelay.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockLaserRelay.java @@ -49,8 +49,8 @@ import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.HitResult; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import javax.annotation.Nullable; import java.util.ArrayList; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockLavaFactoryController.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockLavaFactoryController.java index db2c964f8..df4f90be2 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockLavaFactoryController.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockLavaFactoryController.java @@ -31,8 +31,8 @@ import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.HitResult; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import javax.annotation.Nullable; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockOilGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockOilGenerator.java index 60585bd7f..045f8a150 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockOilGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockOilGenerator.java @@ -15,7 +15,6 @@ import de.ellpeck.actuallyadditions.mod.tile.TileEntityOilGenerator; import net.minecraft.core.BlockPos; import net.minecraft.core.particles.ParticleTypes; import net.minecraft.server.level.ServerLevel; -import net.minecraft.server.level.ServerPlayer; import net.minecraft.util.RandomSource; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; @@ -29,7 +28,6 @@ import net.minecraft.world.level.block.state.BlockState; 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; @@ -70,7 +68,7 @@ public class BlockOilGenerator extends DirectionalBlock.Container { TileEntityOilGenerator generator = (TileEntityOilGenerator) world.getBlockEntity(pos); if (generator != null) { if (!this.tryUseItemOnTank(player, hand, generator.tank)) { - NetworkHooks.openScreen((ServerPlayer) player, generator, pos); + player.openMenu(generator, pos); } } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockPhantom.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockPhantom.java index 077674bcb..27a981791 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockPhantom.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockPhantom.java @@ -43,8 +43,8 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.HitResult; import net.minecraft.world.phys.Vec3; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import javax.annotation.Nullable; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockPlayerInterface.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockPlayerInterface.java index 85515225b..872487dca 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockPlayerInterface.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockPlayerInterface.java @@ -30,8 +30,8 @@ import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.HitResult; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import javax.annotation.Nullable; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockShockSuppressor.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockShockSuppressor.java index fcfbc82c4..c25280622 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockShockSuppressor.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockShockSuppressor.java @@ -23,9 +23,9 @@ import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.event.level.ExplosionEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.neoforge.common.NeoForge; +import net.neoforged.neoforge.event.level.ExplosionEvent; import javax.annotation.Nullable; import java.util.ArrayList; @@ -36,7 +36,7 @@ public class BlockShockSuppressor extends Block implements EntityBlock { public BlockShockSuppressor() { super(ActuallyBlocks.defaultPickProps(20F, 2000.0F)); - MinecraftForge.EVENT_BUS.register(this); + NeoForge.EVENT_BUS.register(this); } @SubscribeEvent diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockVerticalDigger.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockVerticalDigger.java index 0bd109fae..5ecaa42de 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockVerticalDigger.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockVerticalDigger.java @@ -30,8 +30,8 @@ import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.HitResult; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import javax.annotation.Nullable; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/IHudDisplay.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/IHudDisplay.java index bc4debac4..e09065dc5 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/IHudDisplay.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/IHudDisplay.java @@ -16,8 +16,8 @@ import net.minecraft.client.gui.GuiGraphics; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.phys.HitResult; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; public interface IHudDisplay { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/VoxelShapes.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/VoxelShapes.java index aa3e56b86..bc943fee3 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/VoxelShapes.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/VoxelShapes.java @@ -1,7 +1,6 @@ package de.ellpeck.actuallyadditions.mod.blocks; import net.minecraft.world.level.block.Block; -import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.shapes.BooleanOp; import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.VoxelShape; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/base/AACrops.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/base/AACrops.java index a4f70df7f..1345e1172 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/base/AACrops.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/base/AACrops.java @@ -8,8 +8,8 @@ import java.util.function.Supplier; public class AACrops extends CropBlock { Supplier itemSupplier; - public AACrops(Properties p_i48421_1_, Supplier seedSupplier) { - super(p_i48421_1_); + public AACrops(Properties properties, Supplier seedSupplier) { + super(properties); this.itemSupplier = seedSupplier; } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/base/BlockBushBase.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/base/BlockBushBase.java index ded3dfaab..d1a0a39a5 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/base/BlockBushBase.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/base/BlockBushBase.java @@ -10,11 +10,19 @@ package de.ellpeck.actuallyadditions.mod.blocks.base; +import com.mojang.serialization.MapCodec; import net.minecraft.world.level.block.BushBlock; import net.minecraft.world.level.block.SoundType; public class BlockBushBase extends BushBlock { + public static final MapCodec CODEC = simpleCodec(BlockBushBase::new); + public BlockBushBase(Properties properties) { super(properties.sound(SoundType.GRASS)); } + + @Override + protected MapCodec codec() { + return CODEC; + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/base/BlockContainerBase.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/base/BlockContainerBase.java index 82afdaa49..1d17f9b87 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/base/BlockContainerBase.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/base/BlockContainerBase.java @@ -20,7 +20,6 @@ import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.server.level.ServerLevel; -import net.minecraft.server.level.ServerPlayer; import net.minecraft.util.RandomSource; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; @@ -36,9 +35,8 @@ import net.minecraft.world.level.block.EntityBlock; import net.minecraft.world.level.block.RenderShape; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.fluids.FluidUtil; -import net.minecraftforge.fluids.capability.templates.FluidTank; -import net.minecraftforge.network.NetworkHooks; +import net.neoforged.neoforge.fluids.FluidUtil; +import net.neoforged.neoforge.fluids.capability.templates.FluidTank; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -52,7 +50,7 @@ public abstract class BlockContainerBase extends Block implements EntityBlock { if (!world.isClientSide) { BlockEntity tile = world.getBlockEntity(pos); if (expectedInstance.isInstance(tile)) { - NetworkHooks.openScreen((ServerPlayer) player, (MenuProvider) tile, pos); + player.openMenu((MenuProvider) tile); } return InteractionResult.SUCCESS; } @@ -184,14 +182,15 @@ public abstract class BlockContainerBase extends Block implements EntityBlock { } @Override - public void playerWillDestroy(@Nonnull Level world, @Nonnull BlockPos pos, @Nonnull BlockState state, Player player) { - super.playerWillDestroy(world, pos, state, player); + public BlockState playerWillDestroy(@Nonnull Level world, @Nonnull BlockPos pos, @Nonnull BlockState state, Player player) { + BlockState theState = super.playerWillDestroy(world, pos, state, player); if (!player.isCreative()) { BlockEntity tile = world.getBlockEntity(pos); if (tile instanceof TileEntityBase && ((TileEntityBase) tile).stopFromDropping) { player.displayClientMessage(Component.translatable("info." + ActuallyAdditions.MODID + ".machineBroke").withStyle(ChatFormatting.RED), false); } } + return theState; } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/base/BlockPlant.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/base/BlockPlant.java index 7c48ecaa0..8d23cc6dc 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/base/BlockPlant.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/base/BlockPlant.java @@ -28,8 +28,8 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.MapColor; import net.minecraft.world.level.material.PushReaction; import net.minecraft.world.phys.BlockHitResult; -import net.minecraftforge.common.PlantType; -import net.minecraftforge.items.ItemHandlerHelper; +import net.neoforged.neoforge.common.PlantType; +import net.neoforged.neoforge.items.ItemHandlerHelper; import java.util.List; import java.util.function.Supplier; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/render/ReconstructorRenderer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/render/ReconstructorRenderer.java index 25e7a02c4..b06ad3d49 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/render/ReconstructorRenderer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/render/ReconstructorRenderer.java @@ -21,6 +21,9 @@ import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; import net.minecraft.core.Direction; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.phys.Vec3; import javax.annotation.Nonnull; @@ -75,4 +78,12 @@ public class ReconstructorRenderer implements BlockEntityRenderer 0.0f; } + + @Override + public AABB getRenderBoundingBox(TileEntityAtomicReconstructor blockEntity) { + if (blockEntity.getProgress() > 0.0f) + return new AABB(Vec3.atCenterOf(blockEntity.getBlockPos()), Vec3.atCenterOf(blockEntity.getBlockPos()).add(1,1,1).relative(blockEntity.getBlockState().getValue(BlockStateProperties.FACING), 11)); + else + return BlockEntityRenderer.super.getRenderBoundingBox(blockEntity); + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/render/RenderBatteryBox.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/render/RenderBatteryBox.java index 16c3b6606..efdf3dcdd 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/render/RenderBatteryBox.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/render/RenderBatteryBox.java @@ -24,14 +24,16 @@ import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; import net.minecraft.client.resources.language.I18n; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.ItemStack; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.common.capabilities.ForgeCapabilities; -import net.minecraftforge.registries.ForgeRegistries; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; +import net.neoforged.neoforge.capabilities.Capabilities; import org.joml.Matrix4f; +import java.util.Optional; + @OnlyIn(Dist.CLIENT) public class RenderBatteryBox implements BlockEntityRenderer { public RenderBatteryBox(BlockEntityRendererProvider.Context context) { @@ -52,7 +54,7 @@ public class RenderBatteryBox implements BlockEntityRenderer { + Optional.ofNullable(stack.getCapability(Capabilities.EnergyStorage.ITEM)).ifPresent(cap -> { Font font = Minecraft.getInstance().font; String energyTotal = Lang.cleanEnergyValues(cap, false); @@ -91,7 +93,7 @@ public class RenderBatteryBox implements BlockEntityRenderer { public RenderEmpowerer(BlockEntityRendererProvider.Context context) { @@ -51,7 +52,7 @@ public class RenderEmpowerer implements BlockEntityRenderer try { AssetUtil.renderItemInWorld(stack, combinedLight, combinedOverlay, matrices, buffer); } catch (Exception e) { - ActuallyAdditions.LOGGER.error("Something went wrong trying to render an item in an empowerer! The item is " + ForgeRegistries.ITEMS.getKey(stack.getItem()) + "!", e); + ActuallyAdditions.LOGGER.error("Something went wrong trying to render an item in an empowerer! The item is " + BuiltInRegistries.ITEM.getKey(stack.getItem()) + "!", e); } matrices.popPose(); @@ -72,12 +73,12 @@ public class RenderEmpowerer implements BlockEntityRenderer */ if (tile.getCurrentRecipe() != null) { - EmpowererRecipe recipe = tile.getCurrentRecipe(); + RecipeHolder holder = tile.getCurrentRecipe(); for (int i = 0; i <= 3; i++) { Direction facing = Direction.from2DDataValue(i); BlockPos offset = new BlockPos(0,0,0).relative(facing, 3); - AssetUtil.renderLaser(matrices, buffer, new Vec3(0.0d, 0.0d, 0.0d), new Vec3(offset.getX(), offset.getY() + 0.45, offset.getZ()), 80, recipe.getParticleColors(), 1.0f ,0.1F); + AssetUtil.renderLaser(matrices, buffer, new Vec3(0.0d, 0.0d, 0.0d), new Vec3(offset.getX(), offset.getY() + 0.45, offset.getZ()), 80, holder.value().getParticleColors(), 1.0f ,0.1F); } } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/page/PageCrafting.java b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/page/PageCrafting.java index eee7dce40..8d6fb52f7 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/page/PageCrafting.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/page/PageCrafting.java @@ -108,9 +108,9 @@ // if (!this.recipes.isEmpty()) { // for (IRecipe recipe : this.recipes) { // if (recipe != null) { -// ItemStack output = recipe.getResultItem(); -// if (StackUtil.isValid(output)) { -// ItemStack copy = output.copy(); +// ItemStack stack = recipe.getResultItem(); +// if (StackUtil.isValid(stack)) { +// ItemStack copy = stack.copy(); // /* // if (this.isWildcard) { // copy.setItemDamage(Util.WILDCARD); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/page/PageFurnace.java b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/page/PageFurnace.java index bbef79bb3..398357dac 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/page/PageFurnace.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/page/PageFurnace.java @@ -27,23 +27,23 @@ //public class PageFurnace extends BookletPage { // // private final ItemStack input; -// private final ItemStack output; +// private final ItemStack stack; // -// public PageFurnace(int localizationKey, ItemStack output) { -// this(localizationKey, output, 0); +// public PageFurnace(int localizationKey, ItemStack stack) { +// this(localizationKey, stack, 0); // } // -// public PageFurnace(int localizationKey, ItemStack output, int priority) { +// public PageFurnace(int localizationKey, ItemStack stack, int priority) { // super(localizationKey, priority); -// this.output = output; -// this.input = getInputForOutput(output); +// this.stack = stack; +// this.input = getInputForOutput(stack); // } // -// private static ItemStack getInputForOutput(ItemStack output) { +// private static ItemStack getInputForOutput(ItemStack stack) { // for (Map.Entry entry : FurnaceRecipes.instance().getSmeltingList().entrySet()) { // ItemStack stack = entry.getValue(); // if (StackUtil.isValid(stack)) { -// if (stack.sameItem(output)) { +// if (stack.sameItem(stack)) { // return entry.getKey(); // } // } @@ -70,13 +70,13 @@ // super.init(gui, startX, startY); // // gui.addOrModifyItemRenderer(this.input, startX + 23 + 1, startY + 10 + 5, 1F, true); -// gui.addOrModifyItemRenderer(this.output, startX + 23 + 59, startY + 10 + 5, 1F, false); +// gui.addOrModifyItemRenderer(this.stack, startX + 23 + 59, startY + 10 + 5, 1F, false); // } // // @Override // public void getItemStacksForPage(List list) { // super.getItemStacksForPage(list); // -// list.add(this.output); +// list.add(this.stack); // } //} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/config/CommonConfig.java b/src/main/java/de/ellpeck/actuallyadditions/mod/config/CommonConfig.java index 0ea6e80f5..d66fd51a9 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/config/CommonConfig.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/config/CommonConfig.java @@ -2,14 +2,14 @@ package de.ellpeck.actuallyadditions.mod.config; import net.minecraft.world.item.Item; import net.minecraft.world.item.Items; -import net.minecraftforge.common.ForgeConfigSpec; +import net.neoforged.neoforge.common.ModConfigSpec; import java.util.ArrayList; import java.util.List; public class CommonConfig { - private static final ForgeConfigSpec.Builder BUILDER = new ForgeConfigSpec.Builder(); - public static ForgeConfigSpec COMMON_CONFIG; + private static final ModConfigSpec.Builder BUILDER = new ModConfigSpec.Builder(); + public static ModConfigSpec COMMON_CONFIG; static { Other.build(); @@ -19,7 +19,7 @@ public class CommonConfig { } public static class ItemSettings { - public static ForgeConfigSpec.ConfigValue> DRILL_EXTRA_MINING_WHITELIST; + public static ModConfigSpec.ConfigValue> DRILL_EXTRA_MINING_WHITELIST; public static void build() { BUILDER.comment("Item settings").push("itemsSettings"); @@ -35,11 +35,11 @@ public class CommonConfig { } public static class Machines { - public static ForgeConfigSpec.IntValue FARMER_AREA; - public static ForgeConfigSpec.IntValue RECONSTRUCTOR_POWER; - public static ForgeConfigSpec.IntValue OIL_GENERATOR_TRANSFER; - public static ForgeConfigSpec.IntValue MINER_LENS_ENERGY; - public static ForgeConfigSpec.BooleanValue LASER_RELAY_LOSS; + public static ModConfigSpec.IntValue FARMER_AREA; + public static ModConfigSpec.IntValue RECONSTRUCTOR_POWER; + public static ModConfigSpec.IntValue OIL_GENERATOR_TRANSFER; + public static ModConfigSpec.IntValue MINER_LENS_ENERGY; + public static ModConfigSpec.BooleanValue LASER_RELAY_LOSS; public static void build() { BUILDER.comment("Machine Settings").push("machineSettings"); @@ -55,24 +55,24 @@ public class CommonConfig { } public static class Other { - public static ForgeConfigSpec.BooleanValue SOLID_XP_ALWAYS_ORBS; - public static ForgeConfigSpec.BooleanValue DO_UPDATE_CHECK; - public static ForgeConfigSpec.BooleanValue UPDATE_CHECK_VERSION_SPECIFIC; - public static ForgeConfigSpec.BooleanValue DO_CAT_DROPS; - public static ForgeConfigSpec.IntValue FUR_CHANCE; - public static ForgeConfigSpec.BooleanValue WORMS; - public static ForgeConfigSpec.IntValue WORMS_DIE_TIME; - public static ForgeConfigSpec.BooleanValue CTRL_EXTRA_INFO; - public static ForgeConfigSpec.BooleanValue CTRL_INFO_FOR_EXTRA_INFO; - public static ForgeConfigSpec.BooleanValue GIVE_BOOKLET_ON_FIRST_CRAFT; - public static ForgeConfigSpec.BooleanValue DUNGEON_LOOT; - public static ForgeConfigSpec.BooleanValue WATER_BOWL; - public static ForgeConfigSpec.BooleanValue WATER_BOWL_LOSS; - public static ForgeConfigSpec.BooleanValue TINY_COAL_STUFF; - public static ForgeConfigSpec.BooleanValue SUPER_DUPER_HARD_MODE; - public static ForgeConfigSpec.BooleanValue MOST_BLAND_PERSON_EVER; - public static ForgeConfigSpec.ConfigValue REDSTONECONFIGURATOR; - public static ForgeConfigSpec.ConfigValue RELAYCONFIGURATOR; + public static ModConfigSpec.BooleanValue SOLID_XP_ALWAYS_ORBS; + public static ModConfigSpec.BooleanValue DO_UPDATE_CHECK; + public static ModConfigSpec.BooleanValue UPDATE_CHECK_VERSION_SPECIFIC; + public static ModConfigSpec.BooleanValue DO_CAT_DROPS; + public static ModConfigSpec.IntValue FUR_CHANCE; + public static ModConfigSpec.BooleanValue WORMS; + public static ModConfigSpec.IntValue WORMS_DIE_TIME; + public static ModConfigSpec.BooleanValue CTRL_EXTRA_INFO; + public static ModConfigSpec.BooleanValue CTRL_INFO_FOR_EXTRA_INFO; + public static ModConfigSpec.BooleanValue GIVE_BOOKLET_ON_FIRST_CRAFT; + public static ModConfigSpec.BooleanValue DUNGEON_LOOT; + public static ModConfigSpec.BooleanValue WATER_BOWL; + public static ModConfigSpec.BooleanValue WATER_BOWL_LOSS; + public static ModConfigSpec.BooleanValue TINY_COAL_STUFF; + public static ModConfigSpec.BooleanValue SUPER_DUPER_HARD_MODE; + public static ModConfigSpec.BooleanValue MOST_BLAND_PERSON_EVER; + public static ModConfigSpec.ConfigValue REDSTONECONFIGURATOR; + public static ModConfigSpec.ConfigValue RELAYCONFIGURATOR; public static Item redstoneConfigureItem = Items.AIR; public static Item relayConfigureItem = Items.AIR; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/config/conditions/BoolConfigCondition.java b/src/main/java/de/ellpeck/actuallyadditions/mod/config/conditions/BoolConfigCondition.java index 71862a652..2af945086 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/config/conditions/BoolConfigCondition.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/config/conditions/BoolConfigCondition.java @@ -1,24 +1,19 @@ package de.ellpeck.actuallyadditions.mod.config.conditions; -import com.google.gson.JsonObject; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.config.CommonConfig; import net.minecraft.resources.ResourceLocation; -import net.minecraftforge.common.crafting.conditions.ICondition; -import net.minecraftforge.common.crafting.conditions.IConditionSerializer; +import net.neoforged.neoforge.common.conditions.ICondition; -public class BoolConfigCondition implements ICondition { +public record BoolConfigCondition(String boolConfig) implements ICondition { + public static Codec CODEC = RecordCodecBuilder.create( + builder -> builder + .group( + Codec.STRING.fieldOf("boolConfig").forGetter(BoolConfigCondition::boolConfig)) + .apply(builder, BoolConfigCondition::new)); private static final ResourceLocation NAME = new ResourceLocation(ActuallyAdditions.MODID, "bool_config_condition"); - private final String boolConfig; - - public BoolConfigCondition(String config) { - this.boolConfig = config; - } - - @Override - public ResourceLocation getID() { - return NAME; - } @Override public boolean test(IContext condition) { @@ -30,22 +25,13 @@ public class BoolConfigCondition implements ICondition { } } - public static class Serializer implements IConditionSerializer { - public static final BoolConfigCondition.Serializer INSTANCE = new BoolConfigCondition.Serializer(); + @Override + public Codec codec() { + return CODEC; + } - @Override - public void write(JsonObject json, BoolConfigCondition value) { - json.addProperty("config_name", value.boolConfig); - } - - @Override - public BoolConfigCondition read(JsonObject json) { - return new BoolConfigCondition(json.get("config_name").getAsString()); - } - - @Override - public ResourceLocation getID() { - return BoolConfigCondition.NAME; - } + @Override + public String toString() { + return "ConfigEnabled(\"" + boolConfig + "\")"; } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/ActuallyRecipes.java b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/ActuallyRecipes.java index 6d73dba83..7a7b32eb4 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/ActuallyRecipes.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/ActuallyRecipes.java @@ -1,45 +1,46 @@ package de.ellpeck.actuallyadditions.mod.crafting; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.world.item.crafting.RecipeSerializer; import net.minecraft.world.item.crafting.RecipeType; -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 java.util.function.Supplier; public class ActuallyRecipes { - public static final DeferredRegister> SERIALIZERS = DeferredRegister.create(ForgeRegistries.RECIPE_SERIALIZERS, ActuallyAdditions.MODID); + public static final DeferredRegister> SERIALIZERS = DeferredRegister.create(BuiltInRegistries.RECIPE_SERIALIZER, ActuallyAdditions.MODID); public static void init(IEventBus bus) { SERIALIZERS.register(bus); Types.RECIPE_TYPES.register(bus); } - public static final RegistryObject> KEEP_DATA_SHAPED_RECIPE = SERIALIZERS.register(RecipeKeepDataShaped.NAME, RecipeKeepDataShaped.Serializer::new); - public static final RegistryObject> LASER_RECIPE = SERIALIZERS.register(LaserRecipe.NAME, LaserRecipe.Serializer::new); - public static final RegistryObject> EMPOWERING_RECIPE = SERIALIZERS.register(EmpowererRecipe.NAME, EmpowererRecipe.Serializer::new); - public static final RegistryObject> CRUSHING_RECIPE = SERIALIZERS.register(CrushingRecipe.NAME, CrushingRecipe.Serializer::new); - public static final RegistryObject> SOLID_FUEL_RECIPE = SERIALIZERS.register(SolidFuelRecipe.NAME, SolidFuelRecipe.Serializer::new); - public static final RegistryObject> LIQUID_FUEL_RECIPE = SERIALIZERS.register(LiquidFuelRecipe.NAME, LiquidFuelRecipe.Serializer::new); - public static final RegistryObject> PRESSING_RECIPE = SERIALIZERS.register(PressingRecipe.NAME, PressingRecipe.Serializer::new); - public static final RegistryObject> FERMENTING_RECIPE = SERIALIZERS.register(FermentingRecipe.NAME, FermentingRecipe.Serializer::new); - public static final RegistryObject> COLOR_CHANGE_RECIPE = SERIALIZERS.register(ColorChangeRecipe.NAME, ColorChangeRecipe.Serializer::new); - public static final RegistryObject> MINING_LENS_RECIPE = SERIALIZERS.register(MiningLensRecipe.NAME, MiningLensRecipe.Serializer::new); + public static final Supplier> KEEP_DATA_SHAPED_RECIPE = SERIALIZERS.register(RecipeKeepDataShaped.NAME, RecipeKeepDataShaped.Serializer::new); + public static final Supplier> LASER_RECIPE = SERIALIZERS.register(LaserRecipe.NAME, LaserRecipe.Serializer::new); + public static final Supplier> EMPOWERING_RECIPE = SERIALIZERS.register(EmpowererRecipe.NAME, EmpowererRecipe.Serializer::new); + public static final Supplier> CRUSHING_RECIPE = SERIALIZERS.register(CrushingRecipe.NAME, CrushingRecipe.Serializer::new); + public static final Supplier> SOLID_FUEL_RECIPE = SERIALIZERS.register(SolidFuelRecipe.NAME, SolidFuelRecipe.Serializer::new); + public static final Supplier> LIQUID_FUEL_RECIPE = SERIALIZERS.register(LiquidFuelRecipe.NAME, LiquidFuelRecipe.Serializer::new); + public static final Supplier> PRESSING_RECIPE = SERIALIZERS.register(PressingRecipe.NAME, PressingRecipe.Serializer::new); + public static final Supplier> FERMENTING_RECIPE = SERIALIZERS.register(FermentingRecipe.NAME, FermentingRecipe.Serializer::new); + public static final Supplier> COLOR_CHANGE_RECIPE = SERIALIZERS.register(ColorChangeRecipe.NAME, ColorChangeRecipe.Serializer::new); + public static final Supplier> MINING_LENS_RECIPE = SERIALIZERS.register(MiningLensRecipe.NAME, MiningLensRecipe.Serializer::new); public static class Types { - public static final DeferredRegister> RECIPE_TYPES = DeferredRegister.create(ForgeRegistries.RECIPE_TYPES, ActuallyAdditions.MODID); + public static final DeferredRegister> RECIPE_TYPES = DeferredRegister.create(BuiltInRegistries.RECIPE_TYPE, ActuallyAdditions.MODID); - public static final RegistryObject> LASER = RECIPE_TYPES.register("laser", () -> new RecipeType<>() {}); - public static final RegistryObject> EMPOWERING = RECIPE_TYPES.register("empower", () -> new RecipeType<>() {}); - public static final RegistryObject> CRUSHING = RECIPE_TYPES.register("crushing", () -> new RecipeType<>() {}); - public static final RegistryObject> SOLID_FUEL = RECIPE_TYPES.register("solid_fuel", () -> new RecipeType<>() {}); - public static final RegistryObject> LIQUID_FUEL = RECIPE_TYPES.register("liquid_fuel", () -> new RecipeType<>() {}); - public static final RegistryObject> PRESSING = RECIPE_TYPES.register("pressing", () -> new RecipeType<>() {}); - public static final RegistryObject> FERMENTING = RECIPE_TYPES.register("fermenting", () -> new RecipeType<>() {}); - public static final RegistryObject> COLOR_CHANGE = RECIPE_TYPES.register("color_change", () -> new RecipeType<>() {}); - public static final RegistryObject> MINING_LENS = RECIPE_TYPES.register("mining_lens", () -> new RecipeType<>() {}); + public static final Supplier> LASER = RECIPE_TYPES.register("laser", () -> new RecipeType<>() {}); + public static final Supplier> EMPOWERING = RECIPE_TYPES.register("empower", () -> new RecipeType<>() {}); + public static final Supplier> CRUSHING = RECIPE_TYPES.register("crushing", () -> new RecipeType<>() {}); + public static final Supplier> SOLID_FUEL = RECIPE_TYPES.register("solid_fuel", () -> new RecipeType<>() {}); + public static final Supplier> LIQUID_FUEL = RECIPE_TYPES.register("liquid_fuel", () -> new RecipeType<>() {}); + public static final Supplier> PRESSING = RECIPE_TYPES.register("pressing", () -> new RecipeType<>() {}); + public static final Supplier> FERMENTING = RECIPE_TYPES.register("fermenting", () -> new RecipeType<>() {}); + public static final Supplier> COLOR_CHANGE = RECIPE_TYPES.register("color_change", () -> new RecipeType<>() {}); + public static final Supplier> MINING_LENS = RECIPE_TYPES.register("mining_lens", () -> new RecipeType<>() {}); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/ColorChangeRecipe.java b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/ColorChangeRecipe.java index 187da6737..5631d5098 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/ColorChangeRecipe.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/ColorChangeRecipe.java @@ -1,21 +1,18 @@ package de.ellpeck.actuallyadditions.mod.crafting; -import com.google.gson.JsonObject; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; import net.minecraft.core.RegistryAccess; -import net.minecraft.data.recipes.FinishedRecipe; import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.GsonHelper; import net.minecraft.world.Container; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.item.crafting.Recipe; +import net.minecraft.world.item.crafting.RecipeHolder; import net.minecraft.world.item.crafting.RecipeSerializer; import net.minecraft.world.item.crafting.RecipeType; -import net.minecraft.world.level.ItemLike; import net.minecraft.world.level.Level; -import net.minecraftforge.registries.ForgeRegistries; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -26,12 +23,10 @@ public class ColorChangeRecipe implements Recipe { private final Ingredient input; private final ItemStack output; - private final ResourceLocation id; - public ColorChangeRecipe(ResourceLocation id, ItemStack output, Ingredient input) { + public ColorChangeRecipe(ItemStack output, Ingredient input) { this.input = input; this.output = output; - this.id = id; } @Override @@ -59,8 +54,8 @@ public class ColorChangeRecipe implements Recipe { return false; } - public static Optional getRecipeForStack(ItemStack stack) { - return ActuallyAdditionsAPI.COLOR_CHANGE_RECIPES.stream().filter(recipe -> recipe.matches(stack)).findFirst(); + public static Optional> getRecipeForStack(ItemStack stack) { + return ActuallyAdditionsAPI.COLOR_CHANGE_RECIPES.stream().filter(recipe -> recipe.value().matches(stack)).findFirst(); } @Nonnull @@ -69,12 +64,6 @@ public class ColorChangeRecipe implements Recipe { return output.copy(); } - @Nonnull - @Override - public ResourceLocation getId() { - return id; - } - @Nonnull @Override public RecipeSerializer getSerializer() { @@ -87,21 +76,34 @@ public class ColorChangeRecipe implements Recipe { } public static class Serializer implements RecipeSerializer { - @Override - public ColorChangeRecipe fromJson(@Nonnull ResourceLocation pRecipeId, @Nonnull JsonObject pJson) { - Ingredient ingredient = Ingredient.fromJson(GsonHelper.getAsJsonObject(pJson, "ingredient")); - JsonObject resultObject = GsonHelper.getAsJsonObject(pJson, "result"); - ItemStack result = new ItemStack(GsonHelper.getAsItem(resultObject, "item")); + private static final Codec CODEC = RecordCodecBuilder.create( + instance -> instance.group( + ItemStack.RESULT_CODEC.fieldOf("result").forGetter(recipe -> recipe.output), + Ingredient.CODEC_NONEMPTY.fieldOf("ingredient").forGetter(recipe -> recipe.input) + ) + .apply(instance, ColorChangeRecipe::new) + ); - return new ColorChangeRecipe(pRecipeId, result, ingredient); +// @Override +// public ColorChangeRecipe fromJson(@Nonnull ResourceLocation pRecipeId, @Nonnull JsonObject pJson) { +// Ingredient ingredient = Ingredient.fromJson(GsonHelper.getAsJsonObject(pJson, "ingredient")); +// JsonObject resultObject = GsonHelper.getAsJsonObject(pJson, "result"); +// ItemStack result = new ItemStack(GsonHelper.getAsItem(resultObject, "item")); +// +// return new ColorChangeRecipe(pRecipeId, result, ingredient); +// } + + @Override + public Codec codec() { + return CODEC; } @Nullable @Override - public ColorChangeRecipe fromNetwork(@Nonnull ResourceLocation pRecipeId, @Nonnull FriendlyByteBuf pBuffer) { + public ColorChangeRecipe fromNetwork(@Nonnull FriendlyByteBuf pBuffer) { Ingredient ingredient = Ingredient.fromNetwork(pBuffer); ItemStack result = pBuffer.readItem(); - return new ColorChangeRecipe(pRecipeId, result, ingredient); + return new ColorChangeRecipe(result, ingredient); } @Override @@ -110,48 +112,4 @@ public class ColorChangeRecipe implements Recipe { pBuffer.writeItem(pRecipe.output); } } - - public static class Result implements FinishedRecipe { - private final ResourceLocation id; - private final Ingredient itemIngredient; - private final ItemLike output; - - public Result(ResourceLocation id, Ingredient itemIngredient, ItemLike output) { - this.id = id; - this.itemIngredient = itemIngredient; - this.output = output; - } - - @Override - public void serializeRecipeData(JsonObject pJson) { - pJson.add("ingredient", itemIngredient.toJson()); - - JsonObject resultObject = new JsonObject(); - resultObject.addProperty("item", ForgeRegistries.ITEMS.getKey(output.asItem()).toString()); - - pJson.add("result", resultObject); - } - - @Override - public ResourceLocation getId() { - return id; - } - - @Override - public RecipeSerializer getType() { - return ActuallyRecipes.COLOR_CHANGE_RECIPE.get(); - } - - @Nullable - @Override - public JsonObject serializeAdvancement() { - return null; - } - - @Nullable - @Override - public ResourceLocation getAdvancementId() { - return null; - } - } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/CrushingRecipe.java b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/CrushingRecipe.java index bc64f5c7a..6b1044723 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/CrushingRecipe.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/CrushingRecipe.java @@ -1,51 +1,41 @@ package de.ellpeck.actuallyadditions.mod.crafting; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; +import com.mojang.serialization.Codec; +import com.mojang.serialization.DataResult; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.core.NonNullList; import net.minecraft.core.RegistryAccess; -import net.minecraft.data.recipes.FinishedRecipe; import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.GsonHelper; import net.minecraft.world.Container; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.item.crafting.Recipe; import net.minecraft.world.item.crafting.RecipeSerializer; import net.minecraft.world.item.crafting.RecipeType; -import net.minecraft.world.level.ItemLike; import net.minecraft.world.level.Level; -import net.minecraftforge.registries.ForgeRegistries; import javax.annotation.Nonnull; -import javax.annotation.Nullable; public class CrushingRecipe implements Recipe { public static String NAME = "crushing"; - private final ResourceLocation id; protected Ingredient input; - protected ItemStack outputOne; - protected ItemStack outputTwo; - protected float chance1; - protected float chance2; + protected NonNullList outputs; - public CrushingRecipe(ResourceLocation id, Ingredient input, ItemStack outputOne, float chance1, ItemStack outputTwo, float chance2) { - this.id = id; + public CrushingRecipe(Ingredient input, NonNullList outputList) { this.input = input; - this.outputOne = outputOne; - this.outputTwo = outputTwo; - this.chance1 = chance1; - this.chance2 = chance2; + this.outputs = outputList; } public CrushingRecipe(Ingredient input, ItemStack outputOne, float chance1, ItemStack outputTwo, float chance2) { - this.id = new ResourceLocation(ActuallyAdditions.MODID, ForgeRegistries.ITEMS.getKey(input.getItems()[0].getItem()).getPath() + "_crushing"); - this.input = input; - this.outputOne = outputOne; - this.outputTwo = outputTwo; - this.chance1 = chance1; - this.chance2 = chance2; + this(input, createList(new CrushingResult(outputOne, chance1), new CrushingResult(outputTwo, chance2))); + } + + private static NonNullList createList(CrushingResult... results) { + NonNullList list = NonNullList.create(); + for (CrushingResult result : results) { + list.add(result); + } + return list; } @Override @@ -76,13 +66,7 @@ public class CrushingRecipe implements Recipe { @Override @Nonnull public ItemStack getResultItem(RegistryAccess pRegistryAccess) { - return outputOne; - } - - @Override - @Nonnull - public ResourceLocation getId() { - return id; + return this.outputs.get(0).stack.copy(); } @Override @@ -98,137 +82,119 @@ public class CrushingRecipe implements Recipe { } public ItemStack getOutputOne() { - return this.outputOne; + return this.outputs.get(0).stack; } public ItemStack getOutputTwo() { - return this.outputTwo; + return this.outputs.get(1).stack; } public float getFirstChance() { - return this.chance1; + return this.outputs.get(0).chance; } public float getSecondChance() { - return this.chance2; + return this.outputs.get(1).chance; } public Ingredient getInput() { return this.input; } + + public record CrushingResult(ItemStack stack, float chance) { + public static final CrushingResult EMPTY = new CrushingResult(ItemStack.EMPTY, 0.0F); + }; + public static class Serializer implements RecipeSerializer { + private static final Codec RESULT_CODEC = RecordCodecBuilder.create( + instance -> instance.group( + ItemStack.ITEM_WITH_COUNT_CODEC.fieldOf("result").forGetter(result -> result.stack), + Codec.FLOAT.optionalFieldOf("chance", 1.0F).forGetter(recipe -> recipe.chance) + ) + .apply(instance, CrushingResult::new) + ); + + private static final Codec CODEC = RecordCodecBuilder.create( + instance -> instance.group( + Ingredient.CODEC_NONEMPTY.fieldOf("ingredient").forGetter(recipe -> recipe.input), + RESULT_CODEC + .listOf() + .fieldOf("result") + .flatXmap( + array -> { + CrushingResult[] resultArray = array.toArray(CrushingResult[]::new); + NonNullList results = NonNullList.withSize(2, CrushingResult.EMPTY); + if (resultArray.length < 1) { + return DataResult.error(() -> "Recipe must contain at least 1 result"); + } else if (resultArray.length > 2) { + return DataResult.error(() -> "Too many results for crushing recipe. The maximum is: 2"); + } else { + for (int i = 0; i < resultArray.length; i++) { + results.set(i, resultArray[i]); + } + return DataResult.success(results); + } + }, + DataResult::success + ) + .forGetter(recipe -> recipe.outputs) + ) + .apply(instance, CrushingRecipe::new) + ); @Override - @Nonnull - public CrushingRecipe fromJson(@Nonnull ResourceLocation pRecipeId, @Nonnull JsonObject pJson) { - Ingredient ingredient = Ingredient.fromJson(GsonHelper.getAsJsonObject(pJson, "ingredient")); - - JsonArray resultList = GsonHelper.getAsJsonArray(pJson, "result"); - if (resultList.size() < 1) - throw new IllegalStateException(pRecipeId.toString() + ": Recipe must contain at least 1 result item"); - - JsonObject result1 = resultList.get(0).getAsJsonObject(); - int count1 = GsonHelper.getAsInt(result1, "count", 0); - ItemStack output1 = new ItemStack(GsonHelper.getAsItem(result1, "item"), count1); - float chance1 = GsonHelper.getAsFloat(result1, "chance"); - - ItemStack output2 = ItemStack.EMPTY; - float chance2 = 1.0f; - if (resultList.size() > 1) { - JsonObject result2 = resultList.get(1).getAsJsonObject(); - int count2 = GsonHelper.getAsInt(result2, "count", 0); - output2 = new ItemStack(GsonHelper.getAsItem(result2, "item"), count2); - chance2 = GsonHelper.getAsFloat(result2, "chance"); - } - - return new CrushingRecipe(pRecipeId, ingredient, output1, chance1, output2, chance2); + public Codec codec() { + return CODEC; } - @Override - public CrushingRecipe fromNetwork(@Nonnull ResourceLocation pRecipeId, @Nonnull FriendlyByteBuf pBuffer) { - Ingredient ingredient = Ingredient.fromNetwork(pBuffer); - ItemStack output1 = pBuffer.readItem(); - ItemStack output2 = pBuffer.readItem(); - float chance1 = pBuffer.readFloat(); - float chance2 = pBuffer.readFloat(); +// @Override +// @Nonnull +// public CrushingRecipe fromJson(@Nonnull ResourceLocation pRecipeId, @Nonnull JsonObject pJson) { +// Ingredient ingredient = Ingredient.fromJson(GsonHelper.getAsJsonObject(pJson, "ingredient")); +// +// JsonArray resultList = GsonHelper.getAsJsonArray(pJson, "result"); +// if (resultList.size() < 1) +// throw new IllegalStateException(pRecipeId.toString() + ": Recipe must contain at least 1 result item"); +// +// JsonObject result1 = resultList.get(0).getAsJsonObject(); +// int count1 = GsonHelper.getAsInt(result1, "count", 0); +// ItemStack output1 = new ItemStack(GsonHelper.getAsItem(result1, "item"), count1); +// float chance1 = GsonHelper.getAsFloat(result1, "chance"); +// +// ItemStack output2 = ItemStack.EMPTY; +// float chance2 = 1.0f; +// if (resultList.size() > 1) { +// JsonObject result2 = resultList.get(1).getAsJsonObject(); +// int count2 = GsonHelper.getAsInt(result2, "count", 0); +// output2 = new ItemStack(GsonHelper.getAsItem(result2, "item"), count2); +// chance2 = GsonHelper.getAsFloat(result2, "chance"); +// } +// +// return new CrushingRecipe(pRecipeId, ingredient, output1, chance1, output2, chance2); +// } - return new CrushingRecipe(pRecipeId, ingredient, output1, chance1, output2, chance2); + @Override + public CrushingRecipe fromNetwork(@Nonnull FriendlyByteBuf pBuffer) { + Ingredient ingredient = Ingredient.fromNetwork(pBuffer); + + int i = pBuffer.readVarInt(); + + NonNullList nonnulllist = NonNullList.withSize(i, CrushingResult.EMPTY); + for (int j = 0; j < nonnulllist.size(); ++j) { + nonnulllist.set(j, new CrushingResult(pBuffer.readItem(), pBuffer.readFloat())); + } + + return new CrushingRecipe(ingredient, nonnulllist); } @Override public void toNetwork(@Nonnull FriendlyByteBuf pBuffer, CrushingRecipe pRecipe) { pRecipe.input.toNetwork(pBuffer); - pBuffer.writeItem(pRecipe.outputOne); - pBuffer.writeItem(pRecipe.outputTwo); - pBuffer.writeFloat(pRecipe.chance1); - pBuffer.writeFloat(pRecipe.chance2); - } - } - - public static class Result implements FinishedRecipe { - private final ResourceLocation id; - protected Ingredient input; - protected ItemLike outputOne; - protected int countOne; - protected float outputChance1; - protected ItemLike outputTwo; - protected int countTwo; - protected float outputChance2; - - public Result(ResourceLocation id, Ingredient input, ItemLike outputOne, int countOne, float outputChance1, ItemLike outputTwo, int countTwo, float outputChance2) { - this.id = id; - this.countOne = countOne; - this.countTwo = countTwo; - this.input = input; - this.outputOne = outputOne; - this.outputTwo = outputTwo; - this.outputChance1 = outputChance1; - this.outputChance2 = outputChance2; - } - - @Override - public void serializeRecipeData(JsonObject pJson) { - pJson.add("ingredient", input.toJson()); - - JsonObject result1 = new JsonObject(); - result1.addProperty("item", ForgeRegistries.ITEMS.getKey(outputOne.asItem()).toString()); - result1.addProperty("count", countOne); - result1.addProperty("chance", outputChance1); - - JsonObject result2 = new JsonObject(); - result2.addProperty("item", ForgeRegistries.ITEMS.getKey(outputTwo.asItem()).toString()); - result2.addProperty("count", countTwo); - result2.addProperty("chance", outputChance2); - - JsonArray resultList = new JsonArray(); - resultList.add(result1); - resultList.add(result2); - - pJson.add("result", resultList); - } - - @Override - @Nonnull - public ResourceLocation getId() { - return id; - } - - @Override - @Nonnull - public RecipeSerializer getType() { - return ActuallyRecipes.CRUSHING_RECIPE.get(); - } - - @Nullable - @Override - public JsonObject serializeAdvancement() { - return null; - } - - @Nullable - @Override - public ResourceLocation getAdvancementId() { - return null; + pBuffer.writeVarInt(pRecipe.outputs.size()); + for (CrushingResult result : pRecipe.outputs) { + pBuffer.writeItem(result.stack); + pBuffer.writeFloat(result.chance); + } } } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/EmpowererRecipe.java b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/EmpowererRecipe.java index d5258cb3c..51fd80ff6 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/EmpowererRecipe.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/EmpowererRecipe.java @@ -1,21 +1,18 @@ package de.ellpeck.actuallyadditions.mod.crafting; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; +import com.mojang.serialization.Codec; +import com.mojang.serialization.DataResult; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.core.NonNullList; import net.minecraft.core.RegistryAccess; -import net.minecraft.data.recipes.FinishedRecipe; import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.GsonHelper; import net.minecraft.world.Container; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.item.crafting.Recipe; import net.minecraft.world.item.crafting.RecipeSerializer; import net.minecraft.world.item.crafting.RecipeType; -import net.minecraft.world.level.ItemLike; import net.minecraft.world.level.Level; -import net.minecraftforge.registries.ForgeRegistries; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -24,27 +21,19 @@ import java.util.List; public class EmpowererRecipe implements Recipe { public static String NAME = "empowering"; - private final ResourceLocation id; protected final Ingredient input; protected final ItemStack output; - protected final Ingredient modifier1; - protected final Ingredient modifier2; - protected final Ingredient modifier3; - protected final Ingredient modifier4; + protected final NonNullList modifiers; protected final int energyPerStand; protected final int particleColor; protected final int time; - public EmpowererRecipe(ResourceLocation id, ItemStack output, Ingredient input, Ingredient modifier1, Ingredient modifier2, Ingredient modifier3, Ingredient modifier4, int energyPerStand, int particleColor, int time) { - this.id = id; + public EmpowererRecipe(ItemStack output, Ingredient input, NonNullList modifiers, int energyPerStand, int particleColor, int time) { this.input = input; this.output = output; - this.modifier1 = modifier1; - this.modifier2 = modifier2; - this.modifier3 = modifier3; - this.modifier4 = modifier4; + this.modifiers = modifiers; this.energyPerStand = energyPerStand; this.particleColor = particleColor; this.time = time; @@ -57,17 +46,17 @@ public class EmpowererRecipe implements Recipe { ItemStack[] stacks = {stand1, stand2, stand3, stand4}; boolean[] unused = {true, true, true, true}; for (ItemStack s : stacks) { - if (unused[0] && this.modifier1.test(s)) { - matches.add(this.modifier1); + if (unused[0] && this.modifiers.get(0).test(s)) { + matches.add(this.modifiers.get(0)); unused[0] = false; - } else if (unused[1] && this.modifier2.test(s)) { - matches.add(this.modifier2); + } else if (unused[1] && this.modifiers.get(1).test(s)) { + matches.add(this.modifiers.get(1)); unused[1] = false; - } else if (unused[2] && this.modifier3.test(s)) { - matches.add(this.modifier3); + } else if (unused[2] && this.modifiers.get(2).test(s)) { + matches.add(this.modifiers.get(2)); unused[2] = false; - } else if (unused[3] && this.modifier4.test(s)) { - matches.add(this.modifier4); + } else if (unused[3] && this.modifiers.get(3).test(s)) { + matches.add(this.modifiers.get(3)); unused[3] = false; } } @@ -102,12 +91,6 @@ public class EmpowererRecipe implements Recipe { return output; } - @Override - @Nonnull - public ResourceLocation getId() { - return id; - } - @Override @Nonnull public RecipeSerializer getSerializer() { @@ -129,19 +112,19 @@ public class EmpowererRecipe implements Recipe { } public Ingredient getStandOne() { - return this.modifier1; + return this.modifiers.get(0); } public Ingredient getStandTwo() { - return this.modifier2; + return this.modifiers.get(1); } public Ingredient getStandThree() { - return this.modifier3; + return this.modifiers.get(2); } public Ingredient getStandFour() { - return this.modifier4; + return this.modifiers.get(3); } public int getTime() { @@ -157,127 +140,92 @@ public class EmpowererRecipe implements Recipe { } public static class Serializer implements RecipeSerializer { + private static final Codec CODEC = RecordCodecBuilder.create( + instance -> instance.group( + ItemStack.RESULT_CODEC.fieldOf("result").forGetter(recipe -> recipe.output), + Ingredient.CODEC_NONEMPTY.fieldOf("base").forGetter(recipe -> recipe.input), + Ingredient.CODEC_NONEMPTY + .listOf() + .fieldOf("modifiers") + .flatXmap( + list -> { + Ingredient[] aingredient = list + .toArray(Ingredient[]::new); + if (aingredient.length == 0) { + return DataResult.error(() -> "No modifiers for Empowering recipe"); + } else { + return aingredient.length != 4 + ? DataResult.error(() -> "Must have exactly 4 modifiers. has: %s".formatted(aingredient.length)) + : DataResult.success(NonNullList.of(Ingredient.EMPTY, aingredient)); + } + }, + DataResult::success + ) + .forGetter(recipe -> recipe.modifiers), + Codec.INT.fieldOf("energy").forGetter(recipe -> recipe.energyPerStand), + Codec.INT.fieldOf("color").forGetter(recipe -> recipe.particleColor), + Codec.INT.fieldOf("time").forGetter(recipe -> recipe.time) + ) + .apply(instance, EmpowererRecipe::new) + ); + @Override - @Nonnull - public EmpowererRecipe fromJson(@Nonnull ResourceLocation pRecipeId, @Nonnull JsonObject pJson) { - Ingredient base = Ingredient.fromJson(GsonHelper.getAsJsonObject(pJson, "base")); - - JsonArray modifiers = GsonHelper.getAsJsonArray(pJson, "modifiers"); - if (modifiers.size() != 4) - throw new IllegalStateException(pRecipeId.toString() + ": Must have exactly 4 modifiers, has: " + modifiers.size()); - - Ingredient mod1 = Ingredient.fromJson(modifiers.get(0)); - Ingredient mod2 = Ingredient.fromJson(modifiers.get(1)); - Ingredient mod3 = Ingredient.fromJson(modifiers.get(2)); - Ingredient mod4 = Ingredient.fromJson(modifiers.get(3)); - int energy = GsonHelper.getAsInt(pJson, "energy"); - int color = GsonHelper.getAsInt(pJson, "color"); - int time = GsonHelper.getAsInt(pJson, "time"); - JsonObject resultObject = GsonHelper.getAsJsonObject(pJson, "result"); - ItemStack result = new ItemStack(GsonHelper.getAsItem(resultObject, "item")); - - return new EmpowererRecipe(pRecipeId, result, base, mod1, mod2, mod3, mod4, energy, color, time); + public Codec codec() { + return CODEC; } + // @Override +// @Nonnull +// public EmpowererRecipe fromJson(@Nonnull ResourceLocation pRecipeId, @Nonnull JsonObject pJson) { +// Ingredient base = Ingredient.fromJson(GsonHelper.getAsJsonObject(pJson, "base")); +// +// JsonArray modifiers = GsonHelper.getAsJsonArray(pJson, "modifiers"); +// if (modifiers.size() != 4) +// throw new IllegalStateException(pRecipeId.toString() + ": Must have exactly 4 modifiers, has: " + modifiers.size()); +// +// Ingredient mod1 = Ingredient.fromJson(modifiers.get(0)); +// Ingredient mod2 = Ingredient.fromJson(modifiers.get(1)); +// Ingredient mod3 = Ingredient.fromJson(modifiers.get(2)); +// Ingredient mod4 = Ingredient.fromJson(modifiers.get(3)); +// int energy = GsonHelper.getAsInt(pJson, "energy"); +// int color = GsonHelper.getAsInt(pJson, "color"); +// int time = GsonHelper.getAsInt(pJson, "time"); +// JsonObject resultObject = GsonHelper.getAsJsonObject(pJson, "result"); +// ItemStack result = new ItemStack(GsonHelper.getAsItem(resultObject, "item")); +// +// return new EmpowererRecipe(pRecipeId, result, base, mod1, mod2, mod3, mod4, energy, color, time); +// } + @Nullable @Override - public EmpowererRecipe fromNetwork(@Nonnull ResourceLocation pRecipeId, FriendlyByteBuf pBuffer) { + public EmpowererRecipe fromNetwork(FriendlyByteBuf pBuffer) { ItemStack result = pBuffer.readItem(); Ingredient input = Ingredient.fromNetwork(pBuffer); - Ingredient mod1 = Ingredient.fromNetwork(pBuffer); - Ingredient mod2 = Ingredient.fromNetwork(pBuffer); - Ingredient mod3 = Ingredient.fromNetwork(pBuffer); - Ingredient mod4 = Ingredient.fromNetwork(pBuffer); + + int i = pBuffer.readVarInt(); + NonNullList nonnulllist = NonNullList.withSize(i, Ingredient.EMPTY); + for (int j = 0; j < nonnulllist.size(); ++j) { + nonnulllist.set(j, Ingredient.fromNetwork(pBuffer)); + } + int energy = pBuffer.readInt(); int color = pBuffer.readInt(); int time = pBuffer.readInt(); - return new EmpowererRecipe(pRecipeId, result, input, mod1, mod2, mod3, mod4, energy, color, time); + return new EmpowererRecipe(result, input, nonnulllist, energy, color, time); } @Override public void toNetwork(FriendlyByteBuf pBuffer, EmpowererRecipe pRecipe) { pBuffer.writeItem(pRecipe.output); pRecipe.input.toNetwork(pBuffer); - pRecipe.modifier1.toNetwork(pBuffer); - pRecipe.modifier2.toNetwork(pBuffer); - pRecipe.modifier3.toNetwork(pBuffer); - pRecipe.modifier4.toNetwork(pBuffer); + pBuffer.writeVarInt(pRecipe.modifiers.size()); + for (Ingredient modifier : pRecipe.modifiers) { + modifier.toNetwork(pBuffer); + } pBuffer.writeInt(pRecipe.energyPerStand); pBuffer.writeInt(pRecipe.particleColor); pBuffer.writeInt(pRecipe.time); } } - - public static class Result implements FinishedRecipe { - private final ResourceLocation id; - private final Ingredient base; - private final Ingredient mod1; - private final Ingredient mod2; - private final Ingredient mod3; - private final Ingredient mod4; - private final int energy; - private final int color; - private final int time; - private final ItemLike output; - - public Result(ResourceLocation id, ItemLike output, Ingredient input, Ingredient modifier1, Ingredient modifier2, Ingredient modifier3, Ingredient modifier4, int energyPerStand, int particleColor, int time) { - this.id = id; - this.base = input; - this.output = output; - this.mod1 = modifier1; - this.mod2 = modifier2; - this.mod3 = modifier3; - this.mod4 = modifier4; - this.energy = energyPerStand; - this.color = particleColor; - this.time = time; - } - - @Override - public void serializeRecipeData(JsonObject pJson) { - pJson.add("base", base.toJson()); - - JsonArray modifiers = new JsonArray(); - - modifiers.add(mod1.toJson()); - modifiers.add(mod2.toJson()); - modifiers.add(mod3.toJson()); - modifiers.add(mod4.toJson()); - - pJson.add("modifiers", modifiers); - pJson.addProperty("energy", energy); - pJson.addProperty("time", time); - pJson.addProperty("color", color); - - JsonObject resultObject = new JsonObject(); - resultObject.addProperty("item", ForgeRegistries.ITEMS.getKey(output.asItem()).toString()); - - pJson.add("result", resultObject); - } - - @Override - @Nonnull - public ResourceLocation getId() { - return id; - } - - @Override - @Nonnull - public RecipeSerializer getType() { - return ActuallyRecipes.EMPOWERING_RECIPE.get(); - } - - @Nullable - @Override - public JsonObject serializeAdvancement() { - return null; - } - - @Nullable - @Override - public ResourceLocation getAdvancementId() { - return null; - } - } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/FermentingRecipe.java b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/FermentingRecipe.java index 87294bd72..538495e15 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/FermentingRecipe.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/FermentingRecipe.java @@ -1,22 +1,17 @@ package de.ellpeck.actuallyadditions.mod.crafting; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import de.ellpeck.actuallyadditions.mod.inventory.gui.FluidDisplay; import net.minecraft.core.RegistryAccess; -import net.minecraft.data.recipes.FinishedRecipe; import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.GsonHelper; import net.minecraft.world.Container; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Recipe; import net.minecraft.world.item.crafting.RecipeSerializer; import net.minecraft.world.item.crafting.RecipeType; import net.minecraft.world.level.Level; -import net.minecraft.world.level.material.Fluid; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.registries.ForgeRegistries; +import net.neoforged.neoforge.fluids.FluidStack; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -24,7 +19,6 @@ import java.util.Optional; public class FermentingRecipe implements Recipe { public static final String NAME = "fermenting"; - private final ResourceLocation ID; private final FluidStack input; private final FluidStack output; private final int time; @@ -32,8 +26,7 @@ public class FermentingRecipe implements Recipe { private Optional inputDisplay; private Optional outputDisplay; - public FermentingRecipe(ResourceLocation ID, FluidStack input, FluidStack output, int timeIn) { - this.ID = ID; + public FermentingRecipe(FluidStack input, FluidStack output, int timeIn) { this.input = input; this.output = output; this.time = timeIn; @@ -102,12 +95,6 @@ public class FermentingRecipe implements Recipe { return ItemStack.EMPTY; } - @Nonnull - @Override - public ResourceLocation getId() { - return ID; - } - @Nonnull @Override public RecipeSerializer getSerializer() { @@ -121,110 +108,62 @@ public class FermentingRecipe implements Recipe { } public static class Serializer implements RecipeSerializer { - @Nonnull + private static final Codec CODEC = RecordCodecBuilder.create( + instance -> instance.group( + FluidStack.CODEC.fieldOf("ingredient").forGetter(recipe -> recipe.input), + FluidStack.CODEC.fieldOf("result").forGetter(recipe -> recipe.output), + Codec.INT.fieldOf("time").forGetter(recipe -> recipe.time) + ) + .apply(instance, FermentingRecipe::new) + ); + +// @Nonnull +// @Override +// public FermentingRecipe fromJson(@Nonnull ResourceLocation pRecipeId, @Nonnull JsonObject pJson) { +// JsonObject ingredient = pJson.getAsJsonObject("ingredient"); +// +// ResourceLocation fluidRes = new ResourceLocation(GsonHelper.getAsString(ingredient, "fluid")); +// Fluid fluid = BuiltInRegistries.FLUIDS.getValue(fluidRes); +// if (fluid == null) +// throw new JsonParseException("Unknown fluid '" + fluidRes + "'"); +// int inputAmount = GsonHelper.getAsInt(ingredient, "amount", 80); +// FluidStack input = new FluidStack(fluid, inputAmount); +// +// JsonObject result = pJson.getAsJsonObject("result"); +// ResourceLocation fluidOutputRes = new ResourceLocation(GsonHelper.getAsString(result, "fluid")); +// int outputAmount = GsonHelper.getAsInt(result, "amount"); +// Fluid fluidOutput = BuiltInRegistries.FLUIDS.getValue(fluidOutputRes); +// if(fluidOutput == null) +// throw new JsonParseException("Unknown fluid '" + fluidRes + "'"); +// FluidStack output = new FluidStack(fluidOutput, outputAmount); +// +// int time = GsonHelper.getAsInt(pJson, "time", 100); +// +// return new FermentingRecipe(pRecipeId, input, output, time); +// } + + @Override - public FermentingRecipe fromJson(@Nonnull ResourceLocation pRecipeId, @Nonnull JsonObject pJson) { - JsonObject ingredient = pJson.getAsJsonObject("ingredient"); - - ResourceLocation fluidRes = new ResourceLocation(GsonHelper.getAsString(ingredient, "fluid")); - Fluid fluid = ForgeRegistries.FLUIDS.getValue(fluidRes); - if (fluid == null) - throw new JsonParseException("Unknown fluid '" + fluidRes + "'"); - int inputAmount = GsonHelper.getAsInt(ingredient, "amount", 80); - FluidStack input = new FluidStack(fluid, inputAmount); - - JsonObject result = pJson.getAsJsonObject("result"); - ResourceLocation fluidOutputRes = new ResourceLocation(GsonHelper.getAsString(result, "fluid")); - int outputAmount = GsonHelper.getAsInt(result, "amount"); - Fluid fluidOutput = ForgeRegistries.FLUIDS.getValue(fluidOutputRes); - if(fluidOutput == null) - throw new JsonParseException("Unknown fluid '" + fluidRes + "'"); - FluidStack output = new FluidStack(fluidOutput, outputAmount); - - int time = GsonHelper.getAsInt(pJson, "time", 100); - - return new FermentingRecipe(pRecipeId, input, output, time); + public Codec codec() { + return CODEC; } @Nullable @Override - public FermentingRecipe fromNetwork(@Nonnull ResourceLocation pRecipeId, @Nonnull FriendlyByteBuf pBuffer) { - ResourceLocation inputRes = new ResourceLocation(pBuffer.readUtf()); - int inputAmount = pBuffer.readInt(); - Fluid inputFluid = ForgeRegistries.FLUIDS.getValue(inputRes); - if(inputFluid == null) - throw new JsonParseException("Unknown input fluid '" + inputRes + "'"); - FluidStack input = new FluidStack(inputFluid, inputAmount); - - ResourceLocation outputRes = new ResourceLocation(pBuffer.readUtf()); - int outputAmount = pBuffer.readInt(); - Fluid outputFluid = ForgeRegistries.FLUIDS.getValue(outputRes); - if(outputFluid == null) - throw new JsonParseException("Unknown output fluid '" + outputRes + "'"); - FluidStack output = new FluidStack(outputFluid, outputAmount); - + public FermentingRecipe fromNetwork(@Nonnull FriendlyByteBuf pBuffer) { + FluidStack input = FluidStack.readFromPacket(pBuffer); + FluidStack output = FluidStack.readFromPacket(pBuffer); int time = pBuffer.readInt(); - return new FermentingRecipe(pRecipeId, input, output, time); + return new FermentingRecipe(input, output, time); } @Override public void toNetwork(@Nonnull FriendlyByteBuf pBuffer, @Nonnull FermentingRecipe pRecipe) { - pBuffer.writeUtf(ForgeRegistries.FLUIDS.getKey(pRecipe.input.getFluid()).toString()); - pBuffer.writeInt(pRecipe.input.getAmount()); - pBuffer.writeUtf(ForgeRegistries.FLUIDS.getKey(pRecipe.output.getFluid()).toString()); + pRecipe.input.writeToPacket(pBuffer); + pRecipe.output.writeToPacket(pBuffer); pBuffer.writeInt(pRecipe.output.getAmount()); pBuffer.writeInt(pRecipe.time); } } - public static class Result implements FinishedRecipe { - private final ResourceLocation ID; - private final FluidStack input; - private final FluidStack output; - private final int time; - - public Result(ResourceLocation ID, FluidStack input, FluidStack output, int timeIn) { - this.ID = ID; - this.input = input; - this.output = output; - this.time = timeIn; - } - - @Override - public void serializeRecipeData(JsonObject pJson) { - JsonObject ingredient = new JsonObject(); - ingredient.addProperty("fluid", ForgeRegistries.FLUIDS.getKey(input.getFluid()).toString()); - ingredient.addProperty("amount", input.getAmount()); - - JsonObject result = new JsonObject(); - result.addProperty("fluid", ForgeRegistries.FLUIDS.getKey(output.getFluid()).toString()); - result.addProperty("amount", output.getAmount()); - - pJson.add("ingredient", ingredient); - pJson.add("result", result); - pJson.addProperty("time", time); - } - - @Override - public ResourceLocation getId() { - return ID; - } - - @Override - public RecipeSerializer getType() { - return ActuallyRecipes.FERMENTING_RECIPE.get(); - } - - @Nullable - @Override - public JsonObject serializeAdvancement() { - return null; - } - - @Nullable - @Override - public ResourceLocation getAdvancementId() { - return null; - } - } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/LaserRecipe.java b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/LaserRecipe.java index 19a46bff8..de7087b7f 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/LaserRecipe.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/LaserRecipe.java @@ -1,21 +1,18 @@ package de.ellpeck.actuallyadditions.mod.crafting; -import com.google.gson.JsonObject; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; import net.minecraft.core.RegistryAccess; -import net.minecraft.data.recipes.FinishedRecipe; import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.GsonHelper; import net.minecraft.world.Container; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.item.crafting.Recipe; +import net.minecraft.world.item.crafting.RecipeHolder; import net.minecraft.world.item.crafting.RecipeSerializer; import net.minecraft.world.item.crafting.RecipeType; -import net.minecraft.world.level.ItemLike; import net.minecraft.world.level.Level; -import net.minecraftforge.registries.ForgeRegistries; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -27,13 +24,11 @@ public class LaserRecipe implements Recipe { private ItemStack result; private Ingredient itemIngredient; private int energy; - private ResourceLocation id; - public LaserRecipe(ResourceLocation id, ItemStack result, Ingredient itemIngredient, int energy) { + public LaserRecipe(ItemStack result, Ingredient itemIngredient, int energy) { this.result = result; this.itemIngredient = itemIngredient; this.energy = energy; - this.id = id; } public int getEnergy() { @@ -78,11 +73,6 @@ public class LaserRecipe implements Recipe { return result; } - @Override - public ResourceLocation getId() { - return id; - } - @Override public RecipeSerializer getSerializer() { return ActuallyRecipes.LASER_RECIPE.get(); @@ -93,8 +83,8 @@ public class LaserRecipe implements Recipe { return ActuallyRecipes.Types.LASER.get(); } - public static Optional getRecipeForStack(ItemStack stack) { - return ActuallyAdditionsAPI.CONVERSION_LASER_RECIPES.stream().filter(recipe -> recipe.matches(stack)).findFirst(); + public static Optional> getRecipeForStack(ItemStack stack) { + return ActuallyAdditionsAPI.CONVERSION_LASER_RECIPES.stream().filter(recipe -> recipe.value().matches(stack)).findFirst(); } public boolean validInput(ItemStack stack) { @@ -102,23 +92,38 @@ public class LaserRecipe implements Recipe { } public static class Serializer implements RecipeSerializer { - @Override - public LaserRecipe fromJson(@Nonnull ResourceLocation pRecipeId, @Nonnull JsonObject pJson) { - Ingredient ingredient = Ingredient.fromJson(GsonHelper.getAsJsonObject(pJson, "ingredient")); - int energy = GsonHelper.getAsInt(pJson, "energy"); - JsonObject resultObject = GsonHelper.getAsJsonObject(pJson, "result"); - ItemStack result = new ItemStack(GsonHelper.getAsItem(resultObject, "item")); + private static final Codec CODEC = RecordCodecBuilder.create( + instance -> instance.group( + ItemStack.RESULT_CODEC.fieldOf("result").forGetter(recipe -> recipe.result), + Ingredient.CODEC_NONEMPTY.fieldOf("ingredient").forGetter(recipe -> recipe.itemIngredient), + Codec.INT.fieldOf("energy").forGetter(recipe -> recipe.energy) + ) + .apply(instance, LaserRecipe::new) + ); - return new LaserRecipe(pRecipeId, result, ingredient, energy); +// @Override +// public LaserRecipe fromJson(@Nonnull ResourceLocation pRecipeId, @Nonnull JsonObject pJson) { +// Ingredient ingredient = Ingredient.fromJson(GsonHelper.getAsJsonObject(pJson, "ingredient")); +// int energy = GsonHelper.getAsInt(pJson, "energy"); +// JsonObject resultObject = GsonHelper.getAsJsonObject(pJson, "result"); +// ItemStack result = new ItemStack(GsonHelper.getAsItem(resultObject, "item")); +// +// return new LaserRecipe(pRecipeId, result, ingredient, energy); +// } + + + @Override + public Codec codec() { + return CODEC; } @Nullable @Override - public LaserRecipe fromNetwork(@Nonnull ResourceLocation pRecipeId, @Nonnull FriendlyByteBuf pBuffer) { + public LaserRecipe fromNetwork(@Nonnull FriendlyByteBuf pBuffer) { Ingredient ingredient = Ingredient.fromNetwork(pBuffer); int energy = pBuffer.readInt(); ItemStack result = pBuffer.readItem(); - return new LaserRecipe(pRecipeId, result, ingredient, energy); + return new LaserRecipe(result, ingredient, energy); } @Override @@ -128,51 +133,4 @@ public class LaserRecipe implements Recipe { pBuffer.writeItem(pRecipe.result); } } - - public static class Result implements FinishedRecipe { - private ResourceLocation id; - private Ingredient itemIngredient; - private int energy; - private ItemLike output; - - public Result(ResourceLocation id, Ingredient itemIngredient, int energy, ItemLike output) { - this.id = id; - this.itemIngredient = itemIngredient; - this.energy = energy; - this.output = output; - } - - @Override - public void serializeRecipeData(JsonObject pJson) { - pJson.add("ingredient", itemIngredient.toJson()); - pJson.addProperty("energy", energy); - - JsonObject resultObject = new JsonObject(); - resultObject.addProperty("item", ForgeRegistries.ITEMS.getKey(output.asItem()).toString()); - - pJson.add("result", resultObject); - } - - @Override - public ResourceLocation getId() { - return id; - } - - @Override - public RecipeSerializer getType() { - return ActuallyRecipes.LASER_RECIPE.get(); - } - - @Nullable - @Override - public JsonObject serializeAdvancement() { - return null; - } - - @Nullable - @Override - public ResourceLocation getAdvancementId() { - return null; - } - } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/LiquidFuelRecipe.java b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/LiquidFuelRecipe.java index ccd19def2..66bca25d9 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/LiquidFuelRecipe.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/LiquidFuelRecipe.java @@ -1,44 +1,35 @@ package de.ellpeck.actuallyadditions.mod.crafting; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import net.minecraft.core.RegistryAccess; -import net.minecraft.data.recipes.FinishedRecipe; import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.GsonHelper; import net.minecraft.world.Container; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Recipe; import net.minecraft.world.item.crafting.RecipeSerializer; import net.minecraft.world.item.crafting.RecipeType; import net.minecraft.world.level.Level; -import net.minecraft.world.level.material.Fluid; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.registries.ForgeRegistries; +import net.neoforged.neoforge.fluids.FluidStack; import javax.annotation.Nonnull; -import javax.annotation.Nullable; public class LiquidFuelRecipe implements Recipe { public static String NAME = "liquid_fuel"; private FluidStack fuel; private int burnTime; private int totalEnergy; - private ResourceLocation id; /** * Oil generator recipe - * @param id ResourceLocation of the recipe * @param fuel The fluid * @param totalEnergy The total power generated. * @param burnTime The length the fluid burns for, in ticks. */ - public LiquidFuelRecipe(ResourceLocation id, FluidStack fuel, int totalEnergy, int burnTime) { + public LiquidFuelRecipe( FluidStack fuel, int totalEnergy, int burnTime) { this.fuel = fuel; this.burnTime = burnTime; this.totalEnergy = totalEnergy; - this.id = id; } public int getBurnTime() { @@ -88,12 +79,6 @@ public class LiquidFuelRecipe implements Recipe { return ItemStack.EMPTY; } - @Nonnull - @Override - public ResourceLocation getId() { - return id; - } - @Nonnull @Override public RecipeSerializer getSerializer() { @@ -107,96 +92,51 @@ public class LiquidFuelRecipe implements Recipe { } public static class Serializer implements RecipeSerializer { - @Nonnull + private static final Codec CODEC = RecordCodecBuilder.create( + instance -> instance.group( + FluidStack.CODEC.fieldOf("fuel").forGetter(recipe -> recipe.fuel), + Codec.INT.fieldOf("total_energy").forGetter(recipe -> recipe.burnTime), + Codec.INT.fieldOf("burn_time").forGetter(recipe -> recipe.totalEnergy) + ) + .apply(instance, LiquidFuelRecipe::new) + ); + +// @Nonnull +// @Override +// public LiquidFuelRecipe fromJson(@Nonnull ResourceLocation pId, JsonObject pJson) { +// JsonObject ingredient = pJson.getAsJsonObject("ingredient"); +// +// ResourceLocation fluidRes = new ResourceLocation(GsonHelper.getAsString(ingredient, "fluid")); +// Fluid fluid = BuiltInRegistries.FLUIDS.getValue(fluidRes); +// if (fluid == null) +// throw new JsonParseException("Unknown fluid '" + fluidRes + "'"); +// int inputAmount = GsonHelper.getAsInt(ingredient, "amount", 50); +// FluidStack input = new FluidStack(fluid, inputAmount); +// +// JsonObject result = pJson.getAsJsonObject("result"); +// int totalEnergy = result.get("total_energy").getAsInt(); +// int burnTime = result.get("burn_time").getAsInt(); +// return new LiquidFuelRecipe(pId, input, totalEnergy, burnTime); +// } + @Override - public LiquidFuelRecipe fromJson(@Nonnull ResourceLocation pId, JsonObject pJson) { - JsonObject ingredient = pJson.getAsJsonObject("ingredient"); - - ResourceLocation fluidRes = new ResourceLocation(GsonHelper.getAsString(ingredient, "fluid")); - Fluid fluid = ForgeRegistries.FLUIDS.getValue(fluidRes); - if (fluid == null) - throw new JsonParseException("Unknown fluid '" + fluidRes + "'"); - int inputAmount = GsonHelper.getAsInt(ingredient, "amount", 50); - FluidStack input = new FluidStack(fluid, inputAmount); - - JsonObject result = pJson.getAsJsonObject("result"); - int totalEnergy = result.get("total_energy").getAsInt(); - int burnTime = result.get("burn_time").getAsInt(); - return new LiquidFuelRecipe(pId, input, totalEnergy, burnTime); + public Codec codec() { + return CODEC; } @Override - public LiquidFuelRecipe fromNetwork(@Nonnull ResourceLocation pId, @Nonnull FriendlyByteBuf pBuffer) { - ResourceLocation inputRes = new ResourceLocation(pBuffer.readUtf()); - int inputAmount = pBuffer.readInt(); - Fluid inputFluid = ForgeRegistries.FLUIDS.getValue(inputRes); - if(inputFluid == null) - throw new JsonParseException("Unknown input fluid '" + inputRes + "'"); - FluidStack input = new FluidStack(inputFluid, inputAmount); - + public LiquidFuelRecipe fromNetwork(@Nonnull FriendlyByteBuf pBuffer) { + FluidStack input = FluidStack.readFromPacket(pBuffer); int totalEnergy = pBuffer.readInt(); int burnTime = pBuffer.readInt(); - return new LiquidFuelRecipe(pId, input, totalEnergy, burnTime); + return new LiquidFuelRecipe(input, totalEnergy, burnTime); } @Override public void toNetwork(@Nonnull FriendlyByteBuf pBuffer, LiquidFuelRecipe pRecipe) { - pBuffer.writeUtf(ForgeRegistries.FLUIDS.getKey(pRecipe.fuel.getFluid()).toString()); - pBuffer.writeInt(pRecipe.fuel.getAmount()); + pRecipe.fuel.writeToPacket(pBuffer); pBuffer.writeInt(pRecipe.totalEnergy); pBuffer.writeInt(pRecipe.burnTime); } } - - public static class Result implements FinishedRecipe { - private FluidStack fuel; - private int burnTime; - private int totalEnergy; - private ResourceLocation id; - - public Result(ResourceLocation id, FluidStack fuel, int totalEnergy, int burnTime) { - this.fuel = fuel; - this.burnTime = burnTime; - this.totalEnergy = totalEnergy; - this.id = id; - } - - @Override - public void serializeRecipeData(JsonObject pJson) { - JsonObject ingredient = new JsonObject(); - ingredient.addProperty("fluid", ForgeRegistries.FLUIDS.getKey(fuel.getFluid()).toString()); - ingredient.addProperty("amount", fuel.getAmount()); - - JsonObject result = new JsonObject(); - result.addProperty("total_energy", totalEnergy); - result.addProperty("burn_time", burnTime); - - pJson.add("ingredient", ingredient); - pJson.add("result", result); - } - - @Nonnull - @Override - public ResourceLocation getId() { - return id; - } - - @Nonnull - @Override - public RecipeSerializer getType() { - return ActuallyRecipes.LIQUID_FUEL_RECIPE.get(); - } - - @Nullable - @Override - public JsonObject serializeAdvancement() { - return null; - } - - @Nullable - @Override - public ResourceLocation getAdvancementId() { - return null; - } - } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/MiningLensRecipe.java b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/MiningLensRecipe.java index aab82a228..8b13378b5 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/MiningLensRecipe.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/MiningLensRecipe.java @@ -1,11 +1,9 @@ package de.ellpeck.actuallyadditions.mod.crafting; -import com.google.gson.JsonObject; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import net.minecraft.core.RegistryAccess; -import net.minecraft.data.recipes.FinishedRecipe; import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.GsonHelper; import net.minecraft.util.random.Weight; import net.minecraft.util.random.WeightedEntry; import net.minecraft.world.Container; @@ -14,9 +12,7 @@ import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.item.crafting.Recipe; import net.minecraft.world.item.crafting.RecipeSerializer; import net.minecraft.world.item.crafting.RecipeType; -import net.minecraft.world.level.ItemLike; import net.minecraft.world.level.Level; -import net.minecraftforge.registries.ForgeRegistries; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -24,19 +20,16 @@ import javax.annotation.Nullable; public class MiningLensRecipe implements Recipe, WeightedEntry { public static final String NAME = "mining_lens"; - private final ResourceLocation id; private final int weight; private final Ingredient input; //private final int weight; private final ItemStack output; - public MiningLensRecipe(ResourceLocation id, Ingredient input, int weight, ItemStack output) { - super(); + public MiningLensRecipe(Ingredient input, int weight, ItemStack output) { this.weight = weight; this.input = input; //this.weight = weight; this.output = output; - this.id = id; } public Weight getWeight() { @@ -77,11 +70,6 @@ public class MiningLensRecipe implements Recipe, WeightedEntry { return output; } - @Override - public ResourceLocation getId() { - return id; - } - @Override public RecipeSerializer getSerializer() { return ActuallyRecipes.MINING_LENS_RECIPE.get(); @@ -93,23 +81,38 @@ public class MiningLensRecipe implements Recipe, WeightedEntry { } public static class Serializer implements RecipeSerializer { - @Override - public MiningLensRecipe fromJson(@Nonnull ResourceLocation pRecipeId, @Nonnull JsonObject pJson) { - Ingredient ingredient = Ingredient.fromJson(GsonHelper.getAsJsonObject(pJson, "ingredient")); - int weight = GsonHelper.getAsInt(pJson, "weight"); - JsonObject resultObject = GsonHelper.getAsJsonObject(pJson, "result"); - ItemStack result = new ItemStack(GsonHelper.getAsItem(resultObject, "item")); + private static final Codec CODEC = RecordCodecBuilder.create( + instance -> instance.group( + Ingredient.CODEC_NONEMPTY.fieldOf("ingredient").forGetter(recipe -> recipe.input), + Codec.INT.fieldOf("weight").forGetter(recipe -> recipe.weight), + ItemStack.RESULT_CODEC.fieldOf("result").forGetter(recipe -> recipe.output) + ) + .apply(instance, MiningLensRecipe::new) + ); - return new MiningLensRecipe(pRecipeId, ingredient, weight, result); +// @Override +// public MiningLensRecipe fromJson(@Nonnull ResourceLocation pRecipeId, @Nonnull JsonObject pJson) { +// Ingredient ingredient = Ingredient.fromJson(GsonHelper.getAsJsonObject(pJson, "ingredient")); +// int weight = GsonHelper.getAsInt(pJson, "weight"); +// JsonObject resultObject = GsonHelper.getAsJsonObject(pJson, "result"); +// ItemStack result = new ItemStack(GsonHelper.getAsItem(resultObject, "item")); +// +// return new MiningLensRecipe(pRecipeId, ingredient, weight, result); +// } + + + @Override + public Codec codec() { + return CODEC; } @Nullable @Override - public MiningLensRecipe fromNetwork(@Nonnull ResourceLocation pRecipeId, @Nonnull FriendlyByteBuf pBuffer) { + public MiningLensRecipe fromNetwork(@Nonnull FriendlyByteBuf pBuffer) { Ingredient ingredient = Ingredient.fromNetwork(pBuffer); int weight = pBuffer.readInt(); ItemStack result = pBuffer.readItem(); - return new MiningLensRecipe(pRecipeId, ingredient, weight, result); + return new MiningLensRecipe(ingredient, weight, result); } @Override @@ -119,51 +122,4 @@ public class MiningLensRecipe implements Recipe, WeightedEntry { pBuffer.writeItem(pRecipe.output); } } - - public static class Result implements FinishedRecipe { - private final ResourceLocation id; - private final Ingredient itemIngredient; - private final int weight; - private final ItemLike output; - - public Result(ResourceLocation id, Ingredient itemIngredient, int weight, ItemLike output) { - this.id = id; - this.itemIngredient = itemIngredient; - this.weight = weight; - this.output = output; - } - - @Override - public void serializeRecipeData(JsonObject pJson) { - pJson.add("ingredient", itemIngredient.toJson()); - pJson.addProperty("weight", weight); - - JsonObject resultObject = new JsonObject(); - resultObject.addProperty("item", ForgeRegistries.ITEMS.getKey(output.asItem()).toString()); - - pJson.add("result", resultObject); - } - - @Override - public ResourceLocation getId() { - return id; - } - - @Override - public RecipeSerializer getType() { - return ActuallyRecipes.MINING_LENS_RECIPE.get(); - } - - @Nullable - @Override - public JsonObject serializeAdvancement() { - return null; - } - - @Nullable - @Override - public ResourceLocation getAdvancementId() { - return null; - } - } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/PressingRecipe.java b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/PressingRecipe.java index 14616115e..b153d714a 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/PressingRecipe.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/PressingRecipe.java @@ -1,12 +1,9 @@ package de.ellpeck.actuallyadditions.mod.crafting; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import net.minecraft.core.RegistryAccess; -import net.minecraft.data.recipes.FinishedRecipe; import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.GsonHelper; import net.minecraft.world.Container; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Ingredient; @@ -14,21 +11,17 @@ import net.minecraft.world.item.crafting.Recipe; import net.minecraft.world.item.crafting.RecipeSerializer; import net.minecraft.world.item.crafting.RecipeType; import net.minecraft.world.level.Level; -import net.minecraft.world.level.material.Fluid; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.registries.ForgeRegistries; +import net.neoforged.neoforge.fluids.FluidStack; import javax.annotation.Nonnull; import javax.annotation.Nullable; public class PressingRecipe implements Recipe { public static final String NAME = "pressing"; - private final ResourceLocation ID; private final Ingredient input; private final FluidStack output; - public PressingRecipe(ResourceLocation ID, Ingredient input, FluidStack output) { - this.ID = ID; + public PressingRecipe(Ingredient input, FluidStack output) { this.input = input; this.output = output; } @@ -62,11 +55,6 @@ public class PressingRecipe implements Recipe { return ItemStack.EMPTY; } - @Override - public ResourceLocation getId() { - return ID; - } - @Override public RecipeSerializer getSerializer() { return ActuallyRecipes.PRESSING_RECIPE.get(); @@ -78,82 +66,47 @@ public class PressingRecipe implements Recipe { } public static class Serializer implements RecipeSerializer { - @Nonnull - @Override - public PressingRecipe fromJson(@Nonnull ResourceLocation pRecipeId, @Nonnull JsonObject pJson) { - Ingredient ingredient = Ingredient.fromJson(GsonHelper.getAsJsonObject(pJson, "ingredient")); - JsonObject result = pJson.getAsJsonObject("result"); - ResourceLocation fluidRes = new ResourceLocation(GsonHelper.getAsString(result, "fluid")); - int fluidAmount = GsonHelper.getAsInt(result, "amount"); - Fluid fluid = ForgeRegistries.FLUIDS.getValue(fluidRes); - if(fluid == null) - throw new JsonParseException("Unknown fluid '" + fluidRes + "'"); - FluidStack output = new FluidStack(fluid, fluidAmount); + private static final Codec CODEC = RecordCodecBuilder.create( + instance -> instance.group( + Ingredient.CODEC_NONEMPTY.fieldOf("ingredient").forGetter(recipe -> recipe.input), + FluidStack.CODEC.fieldOf("fluid").forGetter(recipe -> recipe.output) + ) + .apply(instance, PressingRecipe::new) + ); - return new PressingRecipe(pRecipeId, ingredient, output); +// @Nonnull +// @Override +// public PressingRecipe fromJson(@Nonnull ResourceLocation pRecipeId, @Nonnull JsonObject pJson) { +// Ingredient ingredient = Ingredient.fromJson(GsonHelper.getAsJsonObject(pJson, "ingredient")); +// JsonObject result = pJson.getAsJsonObject("result"); +// ResourceLocation fluidRes = new ResourceLocation(GsonHelper.getAsString(result, "fluid")); +// int fluidAmount = GsonHelper.getAsInt(result, "amount"); +// Fluid fluid = BuiltInRegistries.FLUIDS.getValue(fluidRes); +// if(fluid == null) +// throw new JsonParseException("Unknown fluid '" + fluidRes + "'"); +// FluidStack output = new FluidStack(fluid, fluidAmount); +// +// return new PressingRecipe(pRecipeId, ingredient, output); +// } + + @Override + public Codec codec() { + return CODEC; } @Nullable @Override - public PressingRecipe fromNetwork(@Nonnull ResourceLocation pRecipeId, @Nonnull FriendlyByteBuf pBuffer) { + public PressingRecipe fromNetwork(@Nonnull FriendlyByteBuf pBuffer) { Ingredient ingredient = Ingredient.fromNetwork(pBuffer); - ResourceLocation fluidRes = new ResourceLocation(pBuffer.readUtf()); - int fluidAmount = pBuffer.readInt(); - Fluid fluid = ForgeRegistries.FLUIDS.getValue(fluidRes); - if(fluid == null) - throw new JsonParseException("Unknown fluid '" + fluidRes + "'"); - FluidStack output = new FluidStack(fluid, fluidAmount); + FluidStack output = FluidStack.readFromPacket(pBuffer); - return new PressingRecipe(pRecipeId, ingredient, output); + return new PressingRecipe(ingredient, output); } @Override public void toNetwork(@Nonnull FriendlyByteBuf pBuffer, @Nonnull PressingRecipe pRecipe) { pRecipe.input.toNetwork(pBuffer); - pBuffer.writeUtf(ForgeRegistries.FLUIDS.getKey(pRecipe.output.getFluid()).toString()); - pBuffer.writeInt(pRecipe.output.getAmount()); - } - } - public static class Result implements FinishedRecipe { - private final ResourceLocation ID; - private final Ingredient input; - private final FluidStack output; - - public Result(ResourceLocation ID, Ingredient input, FluidStack output) { - this.ID = ID; - this.input = input; - this.output = output; - } - - @Override - public void serializeRecipeData(JsonObject pJson) { - pJson.add("ingredient", input.toJson()); - JsonObject result = new JsonObject(); - result.addProperty("fluid", ForgeRegistries.FLUIDS.getKey(output.getFluid()).toString()); - result.addProperty("amount", output.getAmount()); - pJson.add("result", result); - } - - @Override - public ResourceLocation getId() { - return ID; - } - - @Override - public RecipeSerializer getType() { - return ActuallyRecipes.PRESSING_RECIPE.get(); - } - - @Nullable - @Override - public JsonObject serializeAdvancement() { - return null; - } - - @Nullable - @Override - public ResourceLocation getAdvancementId() { - return null; + pRecipe.output.writeToPacket(pBuffer); } } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/SolidFuelRecipe.java b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/SolidFuelRecipe.java index 6b4085979..b3389be30 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/SolidFuelRecipe.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/SolidFuelRecipe.java @@ -1,10 +1,9 @@ package de.ellpeck.actuallyadditions.mod.crafting; -import com.google.gson.JsonObject; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import net.minecraft.core.RegistryAccess; -import net.minecraft.data.recipes.FinishedRecipe; import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.item.crafting.Recipe; @@ -12,20 +11,16 @@ import net.minecraft.world.item.crafting.RecipeSerializer; import net.minecraft.world.item.crafting.RecipeType; import net.minecraft.world.level.Level; -import javax.annotation.Nullable; - public class SolidFuelRecipe implements Recipe { public static String NAME = "solid_fuel"; private Ingredient itemIngredient; private int burnTime; private int totalEnergy; - private ResourceLocation id; - public SolidFuelRecipe(ResourceLocation id, Ingredient itemIngredient, int totalEnergy, int burnTime) { + public SolidFuelRecipe(Ingredient itemIngredient, int totalEnergy, int burnTime) { this.itemIngredient = itemIngredient; this.burnTime = burnTime; this.totalEnergy = totalEnergy; - this.id = id; } public int getBurnTime() { @@ -65,11 +60,6 @@ public class SolidFuelRecipe implements Recipe { return ItemStack.EMPTY; } - @Override - public ResourceLocation getId() { - return id; - } - @Override public RecipeSerializer getSerializer() { return ActuallyRecipes.SOLID_FUEL_RECIPE.get(); @@ -81,20 +71,35 @@ public class SolidFuelRecipe implements Recipe { } public static class Serializer implements RecipeSerializer { + private static final Codec CODEC = RecordCodecBuilder.create( + instance -> instance.group( + Ingredient.CODEC_NONEMPTY.fieldOf("item").forGetter(recipe -> recipe.itemIngredient), + Codec.INT.fieldOf("total_energy").forGetter(recipe -> recipe.totalEnergy), + Codec.INT.fieldOf("burn_time").forGetter(recipe -> recipe.burnTime) + ) + .apply(instance, SolidFuelRecipe::new) + ); + +// @Override +// public SolidFuelRecipe fromJson(ResourceLocation pId, JsonObject pJson) { +// Ingredient itemIngredient = Ingredient.fromJson(pJson.get("item")); +// int totalEnergy = pJson.get("total_energy").getAsInt(); +// int burnTime = pJson.get("burn_time").getAsInt(); +// return new SolidFuelRecipe(pId, itemIngredient, totalEnergy, burnTime); +// } + + @Override - public SolidFuelRecipe fromJson(ResourceLocation pId, JsonObject pJson) { - Ingredient itemIngredient = Ingredient.fromJson(pJson.get("item")); - int totalEnergy = pJson.get("total_energy").getAsInt(); - int burnTime = pJson.get("burn_time").getAsInt(); - return new SolidFuelRecipe(pId, itemIngredient, totalEnergy, burnTime); + public Codec codec() { + return CODEC; } @Override - public SolidFuelRecipe fromNetwork(ResourceLocation pId, FriendlyByteBuf pBuffer) { + public SolidFuelRecipe fromNetwork(FriendlyByteBuf pBuffer) { Ingredient itemIngredient = Ingredient.fromNetwork(pBuffer); int totalEnergy = pBuffer.readInt(); int burnTime = pBuffer.readInt(); - return new SolidFuelRecipe(pId, itemIngredient, totalEnergy, burnTime); + return new SolidFuelRecipe(itemIngredient, totalEnergy, burnTime); } @Override @@ -104,47 +109,4 @@ public class SolidFuelRecipe implements Recipe { pBuffer.writeInt(pRecipe.burnTime); } } - - public static class Result implements FinishedRecipe { - private Ingredient itemIngredient; - private int burnTime; - private int totalEnergy; - private ResourceLocation id; - - public Result(ResourceLocation id, Ingredient itemIngredient, int totalEnergy, int burnTime) { - this.itemIngredient = itemIngredient; - this.burnTime = burnTime; - this.totalEnergy = totalEnergy; - this.id = id; - } - - @Override - public void serializeRecipeData(JsonObject pJson) { - pJson.add("item", itemIngredient.toJson()); - pJson.addProperty("total_energy", totalEnergy); - pJson.addProperty("burn_time", burnTime); - } - - @Override - public ResourceLocation getId() { - return id; - } - - @Override - public RecipeSerializer getType() { - return ActuallyRecipes.SOLID_FUEL_RECIPE.get(); - } - - @Nullable - @Override - public JsonObject serializeAdvancement() { - return null; - } - - @Nullable - @Override - public ResourceLocation getAdvancementId() { - return null; - } - } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/TargetNBTIngredient.java b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/TargetNBTIngredient.java index 4c3cd32db..946e41785 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/TargetNBTIngredient.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/TargetNBTIngredient.java @@ -1,75 +1,75 @@ -package de.ellpeck.actuallyadditions.mod.crafting; - -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.tags.TagKey; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.crafting.Ingredient; -import net.minecraft.world.level.ItemLike; -import net.minecraftforge.common.crafting.IIngredientSerializer; - -import javax.annotation.Nonnull; -import java.util.stream.Stream; - -public class TargetNBTIngredient extends Ingredient { - public TargetNBTIngredient(Stream itemLists) { - super(itemLists); - } - - @Override - @Nonnull - public IIngredientSerializer getSerializer() { - return SERIALIZER; - } - - public static TargetNBTIngredient of(ItemLike itemProvider) { - return new TargetNBTIngredient(Stream.of(new ItemValue(new ItemStack(itemProvider)))); - } - public static TargetNBTIngredient of(ItemStack itemStack) { - return new TargetNBTIngredient(Stream.of(new ItemValue(itemStack))); - } - @Nonnull - public static TargetNBTIngredient of(@Nonnull TagKey tag) { - return new TargetNBTIngredient(Stream.of(new TagValue(tag))); - } - - - - @Override - @Nonnull - public JsonElement toJson() { - JsonObject tmp = super.toJson().getAsJsonObject(); - tmp.addProperty("type", Serializer.NAME.toString()); - return tmp; - } - - - public static Serializer SERIALIZER = new Serializer(); - public static class Serializer implements IIngredientSerializer { - public static ResourceLocation NAME = new ResourceLocation(ActuallyAdditions.MODID, "nbt_target"); - - @Override - @Nonnull - public TargetNBTIngredient parse(FriendlyByteBuf buffer) { - return new TargetNBTIngredient(Stream.generate(() -> new ItemValue(buffer.readItem())).limit(buffer.readVarInt())); - } - - @Override - @Nonnull - public TargetNBTIngredient parse(@Nonnull JsonObject json) { - return new TargetNBTIngredient(Stream.of(Ingredient.valueFromJson(json))); - } - - @Override - public void write(FriendlyByteBuf buffer, TargetNBTIngredient ingredient) { - ItemStack[] items = ingredient.getItems(); - buffer.writeVarInt(items.length); - - for (ItemStack stack : items) - buffer.writeItem(stack); - } - } -} +//package de.ellpeck.actuallyadditions.mod.crafting; +// +//import com.google.gson.JsonElement; +//import com.google.gson.JsonObject; +//import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; +//import net.minecraft.network.FriendlyByteBuf; +//import net.minecraft.resources.ResourceLocation; +//import net.minecraft.tags.TagKey; +//import net.minecraft.world.item.ItemStack; +//import net.minecraft.world.item.crafting.Ingredient; +//import net.minecraft.world.level.ItemLike; +//import net.neoforged.neoforge.common.crafting.IIngredientSerializer; +// +//import javax.annotation.Nonnull; +//import java.util.stream.Stream; +// +//public class TargetNBTIngredient extends Ingredient { TODO: FLANKS PLEASE :D +// public TargetNBTIngredient(Stream itemLists) { +// super(itemLists); +// } +// +// @Override +// @Nonnull +// public IIngredientSerializer getSerializer() { +// return SERIALIZER; +// } +// +// public static TargetNBTIngredient of(ItemLike itemProvider) { +// return new TargetNBTIngredient(Stream.of(new ItemValue(new ItemStack(itemProvider)))); +// } +// public static TargetNBTIngredient of(ItemStack itemStack) { +// return new TargetNBTIngredient(Stream.of(new ItemValue(itemStack))); +// } +// @Nonnull +// public static TargetNBTIngredient of(@Nonnull TagKey tag) { +// return new TargetNBTIngredient(Stream.of(new TagValue(tag))); +// } +// +// +// +// @Override +// @Nonnull +// public JsonElement toJson() { +// JsonObject tmp = super.toJson().getAsJsonObject(); +// tmp.addProperty("type", Serializer.NAME.toString()); +// return tmp; +// } +// +// +// public static Serializer SERIALIZER = new Serializer(); +// public static class Serializer implements IIngredientSerializer { +// public static ResourceLocation NAME = new ResourceLocation(ActuallyAdditions.MODID, "nbt_target"); +// +// @Override +// @Nonnull +// public TargetNBTIngredient parse(FriendlyByteBuf buffer) { +// return new TargetNBTIngredient(Stream.generate(() -> new ItemValue(buffer.readItem())).limit(buffer.readVarInt())); +// } +// +// @Override +// @Nonnull +// public TargetNBTIngredient parse(@Nonnull JsonObject json) { +// return new TargetNBTIngredient(Stream.of(Ingredient.valueFromJson(json))); +// } +// +// @Override +// public void write(FriendlyByteBuf buffer, TargetNBTIngredient ingredient) { +// ItemStack[] items = ingredient.getItems(); +// buffer.writeVarInt(items.length); +// +// for (ItemStack stack : items) +// buffer.writeItem(stack); +// } +// } +//} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/WrappedRecipe.java b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/WrappedRecipe.java index 9b202d371..88bad3acf 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/WrappedRecipe.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/WrappedRecipe.java @@ -4,7 +4,7 @@ import com.google.gson.JsonObject; import net.minecraft.data.recipes.FinishedRecipe; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.crafting.RecipeSerializer; -import net.minecraftforge.registries.ForgeRegistries; +import net.neoforged.neoforge.registries.BuiltInRegistries; import javax.annotation.Nullable; import java.util.function.Consumer; @@ -36,9 +36,9 @@ public class WrappedRecipe implements FinishedRecipe { JsonObject jsonObject = new JsonObject(); if (serializerOverride != null) - jsonObject.addProperty("type", ForgeRegistries.RECIPE_SERIALIZERS.getKey(serializerOverride).toString()); + jsonObject.addProperty("type", BuiltInRegistries.RECIPE_SERIALIZERS.getKey(serializerOverride).toString()); else - jsonObject.addProperty("type", ForgeRegistries.RECIPE_SERIALIZERS.getKey(inner.getType()).toString()); + jsonObject.addProperty("type", BuiltInRegistries.RECIPE_SERIALIZERS.getKey(inner.getType()).toString()); serializeRecipeData(jsonObject); return jsonObject; } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/entity/EntityWorm.java b/src/main/java/de/ellpeck/actuallyadditions/mod/entity/EntityWorm.java index d4abb5856..efb1a8e44 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/entity/EntityWorm.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/entity/EntityWorm.java @@ -13,8 +13,6 @@ package de.ellpeck.actuallyadditions.mod.entity; import de.ellpeck.actuallyadditions.mod.config.CommonConfig; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.protocol.Packet; -import net.minecraft.network.protocol.game.ClientGamePacketListener; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; @@ -27,10 +25,9 @@ import net.minecraft.world.level.block.FarmBlock; import net.minecraft.world.level.block.GrassBlock; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.AABB; -import net.minecraftforge.common.FarmlandWaterManager; -import net.minecraftforge.common.IPlantable; -import net.minecraftforge.common.ticket.AABBTicket; -import net.minecraftforge.network.NetworkHooks; +import net.neoforged.neoforge.common.FarmlandWaterManager; +import net.neoforged.neoforge.common.IPlantable; +import net.neoforged.neoforge.common.ticket.AABBTicket; public class EntityWorm extends Entity { @@ -164,9 +161,4 @@ public class EntityWorm extends Entity { protected void addAdditionalSaveData(CompoundTag compound) { compound.putInt("Timer", this.timer); } - - @Override - public Packet getAddEntityPacket() { - return NetworkHooks.getEntitySpawningPacket(this); - } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/entity/InitEntities.java b/src/main/java/de/ellpeck/actuallyadditions/mod/entity/InitEntities.java index 882aedac6..4af063657 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/entity/InitEntities.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/entity/InitEntities.java @@ -11,8 +11,8 @@ package de.ellpeck.actuallyadditions.mod.entity; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; public final class InitEntities { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/entity/RenderWorm.java b/src/main/java/de/ellpeck/actuallyadditions/mod/entity/RenderWorm.java index f589e1619..30ebccf37 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/entity/RenderWorm.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/entity/RenderWorm.java @@ -24,8 +24,8 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.world.inventory.InventoryMenu; import net.minecraft.world.item.ItemDisplayContext; import net.minecraft.world.item.ItemStack; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; @OnlyIn(Dist.CLIENT) diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/event/ClientEvents.java b/src/main/java/de/ellpeck/actuallyadditions/mod/event/ClientEvents.java index 2037ff64d..734783e4a 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/event/ClientEvents.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/event/ClientEvents.java @@ -33,13 +33,13 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.HitResult; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.client.event.RenderGuiOverlayEvent; -import net.minecraftforge.client.gui.overlay.GuiOverlayManager; -import net.minecraftforge.event.TickEvent; -import net.minecraftforge.event.entity.player.ItemTooltipEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.neoforge.client.event.RenderGuiOverlayEvent; +import net.neoforged.neoforge.client.gui.overlay.GuiOverlayManager; +import net.neoforged.neoforge.event.TickEvent; +import net.neoforged.neoforge.event.entity.player.ItemTooltipEvent; @OnlyIn(Dist.CLIENT) public class ClientEvents { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/event/CommonEvents.java b/src/main/java/de/ellpeck/actuallyadditions/mod/event/CommonEvents.java index a3662246b..49b7868f2 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/event/CommonEvents.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/event/CommonEvents.java @@ -23,6 +23,7 @@ import de.ellpeck.actuallyadditions.mod.tile.FilterSettings; import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA; import de.ellpeck.actuallyadditions.mod.util.ItemUtil; import de.ellpeck.actuallyadditions.mod.util.StackUtil; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.entity.monster.Spider; @@ -30,13 +31,12 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.event.entity.living.LivingDropsEvent; -import net.minecraftforge.event.entity.player.EntityItemPickupEvent; -import net.minecraftforge.event.entity.player.PlayerEvent; -import net.minecraftforge.event.level.BlockEvent; -import net.minecraftforge.eventbus.api.Event; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.registries.ForgeRegistries; +import net.neoforged.bus.api.Event; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.neoforge.event.entity.living.LivingDropsEvent; +import net.neoforged.neoforge.event.entity.player.EntityItemPickupEvent; +import net.neoforged.neoforge.event.entity.player.PlayerEvent; +import net.neoforged.neoforge.event.level.BlockEvent; import java.util.Locale; @@ -168,7 +168,7 @@ public class CommonEvents { if (CommonConfig.Other.GIVE_BOOKLET_ON_FIRST_CRAFT.get()) { if (!event.getEntity().level().isClientSide && StackUtil.isValid(event.getCrafting()) && event.getCrafting().getItem() != ActuallyItems.ITEM_BOOKLET.get()) { - String name = ForgeRegistries.ITEMS.getKey(event.getCrafting().getItem()).toString(); + String name = BuiltInRegistries.ITEM.getKey(event.getCrafting().getItem()).toString(); if (name != null && name.toLowerCase(Locale.ROOT).contains(ActuallyAdditions.MODID)) { PlayerData.PlayerSave save = PlayerData.getDataFromPlayer(event.getEntity()); if (save != null && !save.bookGottenAlready) { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/fluids/AATank.java b/src/main/java/de/ellpeck/actuallyadditions/mod/fluids/AATank.java index dd05ac97d..2d8d5bf25 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/fluids/AATank.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/fluids/AATank.java @@ -1,7 +1,7 @@ package de.ellpeck.actuallyadditions.mod.fluids; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.capability.templates.FluidTank; +import net.neoforged.neoforge.fluids.FluidStack; +import net.neoforged.neoforge.fluids.capability.templates.FluidTank; import javax.annotation.Nonnull; import java.util.function.Predicate; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/fluids/FluidAA.java b/src/main/java/de/ellpeck/actuallyadditions/mod/fluids/FluidAA.java index 6665b48dd..130619433 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/fluids/FluidAA.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/fluids/FluidAA.java @@ -25,11 +25,11 @@ import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.material.FlowingFluid; import net.minecraft.world.level.material.Fluid; import net.minecraft.world.level.pathfinder.BlockPathTypes; -import net.minecraftforge.client.extensions.common.IClientFluidTypeExtensions; -import net.minecraftforge.common.SoundActions; -import net.minecraftforge.fluids.FluidType; -import net.minecraftforge.fluids.ForgeFlowingFluid; -import net.minecraftforge.registries.RegistryObject; +import net.neoforged.neoforge.client.extensions.common.IClientFluidTypeExtensions; +import net.neoforged.neoforge.common.SoundActions; +import net.neoforged.neoforge.fluids.BaseFlowingFluid; +import net.neoforged.neoforge.fluids.FluidType; +import net.neoforged.neoforge.registries.DeferredItem; import java.util.function.Consumer; import java.util.function.Supplier; @@ -38,19 +38,19 @@ public class FluidAA implements Supplier { private String name; private final ResourceLocation stillTexture; private final ResourceLocation flowingTexture; - private RegistryObject fluidType; - private RegistryObject source; - private RegistryObject flowing; - private RegistryObject fluidBlock; - private RegistryObject bucket; + private Supplier fluidType; + private Supplier source; + private Supplier flowing; + private Supplier fluidBlock; + private DeferredItem bucket; public String getName() { return name; } - public static ForgeFlowingFluid.Properties createProperties(Supplier type, Supplier still, Supplier flowing, - RegistryObject bucket, Supplier block) { - return new ForgeFlowingFluid.Properties(type, still, flowing) + public static BaseFlowingFluid.Properties createProperties(Supplier type, Supplier still, Supplier flowing, + DeferredItem bucket, Supplier block) { + return new BaseFlowingFluid.Properties(type, still, flowing) .bucket(bucket).block(block); } @@ -76,9 +76,9 @@ public class FluidAA implements Supplier { } }); - source = InitFluids.FLUIDS.register(name, () -> new ForgeFlowingFluid.Source(createProperties(fluidType, source, flowing, bucket, fluidBlock))); - flowing = InitFluids.FLUIDS.register(name + "_flowing", () -> new ForgeFlowingFluid.Flowing(createProperties(fluidType, source, flowing, bucket, fluidBlock))); - fluidBlock = ActuallyBlocks.BLOCKS.register(name, () -> new LiquidBlock(source, BlockBehaviour.Properties.copy(Blocks.WATER))); + source = InitFluids.FLUIDS.register(name, () -> new BaseFlowingFluid.Source(createProperties(fluidType, source, flowing, bucket, fluidBlock))); + flowing = InitFluids.FLUIDS.register(name + "_flowing", () -> new BaseFlowingFluid.Flowing(createProperties(fluidType, source, flowing, bucket, fluidBlock))); + fluidBlock = ActuallyBlocks.BLOCKS.register(name, () -> new LiquidBlock(source, BlockBehaviour.Properties.ofFullCopy(Blocks.WATER))); bucket = ActuallyItems.ITEMS.register(name + "_bucket", () -> new BucketItem(source, new Item.Properties().craftRemainder(Items.BUCKET).stacksTo(1))); } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/fluids/InitFluids.java b/src/main/java/de/ellpeck/actuallyadditions/mod/fluids/InitFluids.java index a828b639c..19981eb37 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/fluids/InitFluids.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/fluids/InitFluids.java @@ -11,17 +11,17 @@ package de.ellpeck.actuallyadditions.mod.fluids; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; -import net.minecraft.world.level.block.Block; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.world.level.material.Fluid; -import net.minecraftforge.eventbus.api.IEventBus; -import net.minecraftforge.fluids.FluidType; -import net.minecraftforge.registries.DeferredRegister; -import net.minecraftforge.registries.ForgeRegistries; +import net.neoforged.bus.api.IEventBus; +import net.neoforged.neoforge.fluids.FluidType; +import net.neoforged.neoforge.registries.DeferredRegister; +import net.neoforged.neoforge.registries.NeoForgeRegistries; public final class InitFluids { - public static final DeferredRegister FLUIDS = DeferredRegister.create(ForgeRegistries.FLUIDS, ActuallyAdditions.MODID); - public static final DeferredRegister FLUID_TYPES = DeferredRegister.create(ForgeRegistries.Keys.FLUID_TYPES, ActuallyAdditions.MODID); - public static final DeferredRegister FLUID_BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, ActuallyAdditions.MODID); + public static final DeferredRegister FLUIDS = DeferredRegister.create(BuiltInRegistries.FLUID, ActuallyAdditions.MODID); + public static final DeferredRegister FLUID_TYPES = DeferredRegister.create(NeoForgeRegistries.Keys.FLUID_TYPES, ActuallyAdditions.MODID); + public static final DeferredRegister.Blocks FLUID_BLOCKS = DeferredRegister.createBlocks(ActuallyAdditions.MODID); public static final FluidAA CANOLA_OIL = new FluidAA("canola_oil", "fluid/canola_oil"); public static final FluidAA REFINED_CANOLA_OIL = new FluidAA("refined_canola_oil", "fluid/refined_canola_oil"); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/fluids/OutputOnlyFluidTank.java b/src/main/java/de/ellpeck/actuallyadditions/mod/fluids/OutputOnlyFluidTank.java index ceffa015d..d7dd5bfb4 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/fluids/OutputOnlyFluidTank.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/fluids/OutputOnlyFluidTank.java @@ -1,7 +1,7 @@ package de.ellpeck.actuallyadditions.mod.fluids; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.capability.templates.FluidTank; +import net.neoforged.neoforge.fluids.FluidStack; +import net.neoforged.neoforge.fluids.capability.templates.FluidTank; import java.util.function.Predicate; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/gen/village/BasicTradeList.java b/src/main/java/de/ellpeck/actuallyadditions/mod/gen/village/BasicTradeList.java index a19abff19..983d7e3f1 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/gen/village/BasicTradeList.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/gen/village/BasicTradeList.java @@ -24,18 +24,18 @@ // // private final ItemStack input; // private final PriceInfo inputAmount; -// private final ItemStack output; +// private final ItemStack stack; // private final PriceInfo outputAmount; // -// public BasicTradeList(ItemStack input, PriceInfo inputAmount, ItemStack output, PriceInfo outputAmount) { +// public BasicTradeList(ItemStack input, PriceInfo inputAmount, ItemStack stack, PriceInfo outputAmount) { // this.input = input; // this.inputAmount = inputAmount; -// this.output = output; +// this.stack = stack; // this.outputAmount = outputAmount; // } // -// public BasicTradeList(PriceInfo emeraldInput, ItemStack output, PriceInfo outputAmount) { -// this(new ItemStack(Items.EMERALD), emeraldInput, output, outputAmount); +// public BasicTradeList(PriceInfo emeraldInput, ItemStack stack, PriceInfo outputAmount) { +// this(new ItemStack(Items.EMERALD), emeraldInput, stack, outputAmount); // } // // public BasicTradeList(ItemStack input, PriceInfo inputAmount, PriceInfo emeraldOutput) { @@ -46,7 +46,7 @@ // public void addMerchantRecipe(IMerchant merchant, MerchantRecipeList recipeList, Random random) { // ItemStack in = this.input.copy(); // in.setCount(this.inputAmount.getPrice(random)); -// ItemStack out = this.output.copy(); +// ItemStack out = this.stack.copy(); // out.setCount(this.outputAmount.getPrice(random)); // recipeList.add(new MerchantRecipe(in, out)); // } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ActuallyContainers.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ActuallyContainers.java index 896f8ec26..a83d49703 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ActuallyContainers.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ActuallyContainers.java @@ -1,41 +1,42 @@ package de.ellpeck.actuallyadditions.mod.inventory; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.world.inventory.MenuType; -import net.minecraftforge.common.extensions.IForgeMenuType; -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.neoforge.registries.DeferredRegister; + +import java.util.function.Supplier; public class ActuallyContainers { - public static final DeferredRegister> CONTAINERS = DeferredRegister.create(ForgeRegistries.MENU_TYPES, ActuallyAdditions.MODID); + public static final DeferredRegister> CONTAINERS = DeferredRegister.create(BuiltInRegistries.MENU, ActuallyAdditions.MODID); - public static final RegistryObject> BAG_CONTAINER = CONTAINERS.register("bag_container", () -> IForgeMenuType.create(SackContainer::fromNetwork)); - public static final RegistryObject> BIO_REACTOR_CONTAINER = CONTAINERS.register("bioreactor_container", () -> IForgeMenuType.create(ContainerBioReactor::fromNetwork)); - public static final RegistryObject> BREAKER_CONTAINER = CONTAINERS.register("breaker_container", () -> IForgeMenuType.create(ContainerBreaker::fromNetwork)); - public static final RegistryObject> CANOLA_PRESS_CONTAINER = CONTAINERS.register("canola_press_container", () -> IForgeMenuType.create(ContainerCanolaPress::fromNetwork)); - public static final RegistryObject> COAL_GENERATOR_CONTAINER = CONTAINERS.register("coal_generator_container", () -> IForgeMenuType.create(ContainerCoalGenerator::fromNetwork)); - public static final RegistryObject> COFFEE_MACHINE_CONTAINER = CONTAINERS.register("coffee_machine_container", () -> IForgeMenuType.create(ContainerCoffeeMachine::fromNetwork)); - public static final RegistryObject> DIRECTIONAL_BREAKER_CONTAINER = CONTAINERS.register("directional_breaker_container", () -> IForgeMenuType.create(ContainerDirectionalBreaker::fromNetwork)); - public static final RegistryObject> DRILL_CONTAINER = CONTAINERS.register("drill_container", () -> IForgeMenuType.create(ContainerDrill::fromNetwork)); - public static final RegistryObject> DROPPER_CONTAINER = CONTAINERS.register("dropper_container", () -> IForgeMenuType.create(ContainerDropper::fromNetwork)); - public static final RegistryObject> ENERVATOR_CONTAINER = CONTAINERS.register("enervator_container", () -> IForgeMenuType.create(ContainerEnervator::fromNetwork)); - public static final RegistryObject> ENERGIZER_CONTAINER = CONTAINERS.register("energizer_container", () -> IForgeMenuType.create(ContainerEnergizer::fromNetwork)); + public static final Supplier> BAG_CONTAINER = CONTAINERS.register("bag_container", () -> IMenuTypeExtension.create(SackContainer::fromNetwork)); + public static final Supplier> BIO_REACTOR_CONTAINER = CONTAINERS.register("bioreactor_container", () -> IMenuTypeExtension.create(ContainerBioReactor::fromNetwork)); + public static final Supplier> BREAKER_CONTAINER = CONTAINERS.register("breaker_container", () -> IMenuTypeExtension.create(ContainerBreaker::fromNetwork)); + public static final Supplier> CANOLA_PRESS_CONTAINER = CONTAINERS.register("canola_press_container", () -> IMenuTypeExtension.create(ContainerCanolaPress::fromNetwork)); + public static final Supplier> COAL_GENERATOR_CONTAINER = CONTAINERS.register("coal_generator_container", () -> IMenuTypeExtension.create(ContainerCoalGenerator::fromNetwork)); + public static final Supplier> COFFEE_MACHINE_CONTAINER = CONTAINERS.register("coffee_machine_container", () -> IMenuTypeExtension.create(ContainerCoffeeMachine::fromNetwork)); + public static final Supplier> DIRECTIONAL_BREAKER_CONTAINER = CONTAINERS.register("directional_breaker_container", () -> IMenuTypeExtension.create(ContainerDirectionalBreaker::fromNetwork)); + public static final Supplier> DRILL_CONTAINER = CONTAINERS.register("drill_container", () -> IMenuTypeExtension.create(ContainerDrill::fromNetwork)); + public static final Supplier> DROPPER_CONTAINER = CONTAINERS.register("dropper_container", () -> IMenuTypeExtension.create(ContainerDropper::fromNetwork)); + public static final Supplier> ENERVATOR_CONTAINER = CONTAINERS.register("enervator_container", () -> IMenuTypeExtension.create(ContainerEnervator::fromNetwork)); + public static final Supplier> ENERGIZER_CONTAINER = CONTAINERS.register("energizer_container", () -> IMenuTypeExtension.create(ContainerEnergizer::fromNetwork)); - public static final RegistryObject> FARMER_CONTAINER = CONTAINERS.register("farmer_container", () -> IForgeMenuType.create(ContainerFarmer::fromNetwork)); - public static final RegistryObject> FEEDER_CONTAINER = CONTAINERS.register("feeder_container", () -> IForgeMenuType.create(ContainerFeeder::fromNetwork)); - public static final RegistryObject> FERMENTING_BARREL_CONTAINER = CONTAINERS.register("fermenting_barrel_container", () -> IForgeMenuType.create(ContainerFermentingBarrel::fromNetwork)); - public static final RegistryObject> FILTER_CONTAINER = CONTAINERS.register("filter_container", () -> IForgeMenuType.create(ContainerFilter::fromNetwork)); - public static final RegistryObject> FIREWORK_BOX_CONTAINER = CONTAINERS.register("firework_box_container", () -> IForgeMenuType.create(ContainerFireworkBox::fromNetwork)); - public static final RegistryObject> FLUID_COLLECTOR_CONTAINER = CONTAINERS.register("fluid_collector_container", () -> IForgeMenuType.create(ContainerFluidCollector::fromNetwork)); - public static final RegistryObject> FURNACE_DOUBLE_CONTAINER = CONTAINERS.register("furnace_double_container", () -> IForgeMenuType.create(ContainerFurnaceDouble::fromNetwork)); - public static final RegistryObject> GRINDER_CONTAINER = CONTAINERS.register("grinder_container", () -> IForgeMenuType.create(CrusherContainer::fromNetwork)); - public static final RegistryObject> LASER_RELAY_ITEM_WHITELIST_CONTAINER = CONTAINERS.register("laser_relay_item_whitelist_container", () -> IForgeMenuType.create(ContainerLaserRelayItemWhitelist::fromNetwork)); - public static final RegistryObject> MINER_CONTAINER = CONTAINERS.register("miner_container", () -> IForgeMenuType.create(ContainerMiner::fromNetwork)); - public static final RegistryObject> OIL_GENERATOR_CONTAINER = CONTAINERS.register("oil_generator_container", () -> IForgeMenuType.create(ContainerOilGenerator::fromNetwork)); - public static final RegistryObject> PHANTOM_PLACER_CONTAINER = CONTAINERS.register("phantom_placer_container", () -> IForgeMenuType.create(ContainerPhantomPlacer::fromNetwork)); - public static final RegistryObject> RANGED_COLLECTOR_CONTAINER = CONTAINERS.register("ranged_collector_container", () -> IForgeMenuType.create(ContainerRangedCollector::fromNetwork)); - public static final RegistryObject> XPSOLIDIFIER_CONTAINER = CONTAINERS.register("xpsolidifier_container", () -> IForgeMenuType.create(ContainerXPSolidifier::fromNetwork)); + public static final Supplier> FARMER_CONTAINER = CONTAINERS.register("farmer_container", () -> IMenuTypeExtension.create(ContainerFarmer::fromNetwork)); + public static final Supplier> FEEDER_CONTAINER = CONTAINERS.register("feeder_container", () -> IMenuTypeExtension.create(ContainerFeeder::fromNetwork)); + public static final Supplier> FERMENTING_BARREL_CONTAINER = CONTAINERS.register("fermenting_barrel_container", () -> IMenuTypeExtension.create(ContainerFermentingBarrel::fromNetwork)); + public static final Supplier> FILTER_CONTAINER = CONTAINERS.register("filter_container", () -> IMenuTypeExtension.create(ContainerFilter::fromNetwork)); + public static final Supplier> FIREWORK_BOX_CONTAINER = CONTAINERS.register("firework_box_container", () -> IMenuTypeExtension.create(ContainerFireworkBox::fromNetwork)); + public static final Supplier> FLUID_COLLECTOR_CONTAINER = CONTAINERS.register("fluid_collector_container", () -> IMenuTypeExtension.create(ContainerFluidCollector::fromNetwork)); + public static final Supplier> FURNACE_DOUBLE_CONTAINER = CONTAINERS.register("furnace_double_container", () -> IMenuTypeExtension.create(ContainerFurnaceDouble::fromNetwork)); + public static final Supplier> GRINDER_CONTAINER = CONTAINERS.register("grinder_container", () -> IMenuTypeExtension.create(CrusherContainer::fromNetwork)); + public static final Supplier> LASER_RELAY_ITEM_WHITELIST_CONTAINER = CONTAINERS.register("laser_relay_item_whitelist_container", () -> IMenuTypeExtension.create(ContainerLaserRelayItemWhitelist::fromNetwork)); + public static final Supplier> MINER_CONTAINER = CONTAINERS.register("miner_container", () -> IMenuTypeExtension.create(ContainerMiner::fromNetwork)); + public static final Supplier> OIL_GENERATOR_CONTAINER = CONTAINERS.register("oil_generator_container", () -> IMenuTypeExtension.create(ContainerOilGenerator::fromNetwork)); + public static final Supplier> PHANTOM_PLACER_CONTAINER = CONTAINERS.register("phantom_placer_container", () -> IMenuTypeExtension.create(ContainerPhantomPlacer::fromNetwork)); + public static final Supplier> RANGED_COLLECTOR_CONTAINER = CONTAINERS.register("ranged_collector_container", () -> IMenuTypeExtension.create(ContainerRangedCollector::fromNetwork)); + public static final Supplier> XPSOLIDIFIER_CONTAINER = CONTAINERS.register("xpsolidifier_container", () -> IMenuTypeExtension.create(ContainerXPSolidifier::fromNetwork)); } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerCoalGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerCoalGenerator.java index 8783f8246..b044353fa 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerCoalGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerCoalGenerator.java @@ -19,7 +19,7 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; -import net.minecraftforge.common.ForgeHooks; +import net.neoforged.neoforge.common.CommonHooks; import java.util.Objects; @@ -63,7 +63,7 @@ public class ContainerCoalGenerator extends AbstractContainerMenu { //Other Slots in Inventory excluded if (slot >= inventoryStart) { //Shift from Inventory - if (ForgeHooks.getBurnTime(newStack, null) > 0) { + if (CommonHooks.getBurnTime(newStack, null) > 0) { if (!this.moveItemStackTo(newStack, 0, 1, false)) { return ItemStack.EMPTY; } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerEnergizer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerEnergizer.java index a2e1d2b3a..ae8af6a62 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerEnergizer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerEnergizer.java @@ -23,7 +23,7 @@ import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ArmorItem; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.enchantment.EnchantmentHelper; -import net.minecraftforge.common.capabilities.ForgeCapabilities; +import net.neoforged.neoforge.capabilities.Capabilities; import java.util.Objects; @@ -43,7 +43,7 @@ public class ContainerEnergizer extends AbstractContainerMenu { this.addSlot(new SlotItemHandlerUnconditioned(this.energizer.inv, 0, 76, 73) { @Override public boolean mayPlace(ItemStack stack) { - return super.mayPlace(stack) && stack.getCapability(ForgeCapabilities.ENERGY, null).isPresent(); + return super.mayPlace(stack) && stack.getCapability(Capabilities.EnergyStorage.ITEM, null) != null; } }); this.addSlot(new SlotOutput(this.energizer.inv, 1, 76, 42)); @@ -110,7 +110,7 @@ public class ContainerEnergizer extends AbstractContainerMenu { //Other Slots in Inventory excluded else if (slot >= inventoryStart) { //Shift from Inventory - if (newStack.getCapability(ForgeCapabilities.ENERGY, null).isPresent()) { + if (newStack.getCapability(Capabilities.EnergyStorage.ITEM, null) != null) { if (!this.moveItemStackTo(newStack, 0, 1, false)) { return ItemStack.EMPTY; } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerEnervator.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerEnervator.java index c8b535ab7..2e4a64a88 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerEnervator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerEnervator.java @@ -22,7 +22,7 @@ import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ArmorItem; import net.minecraft.world.item.ItemStack; -import net.minecraftforge.common.capabilities.ForgeCapabilities; +import net.neoforged.neoforge.capabilities.Capabilities; import java.util.Objects; @@ -98,7 +98,7 @@ public class ContainerEnervator extends AbstractContainerMenu { //Other Slots in Inventory excluded else if (slot >= inventoryStart) { //Shift from Inventory - if (newStack.getCapability(ForgeCapabilities.ENERGY).isPresent()) { + if (newStack.getCapability(Capabilities.EnergyStorage.ITEM) != null) { if (!this.moveItemStackTo(newStack, 0, 1, false)) { return ItemStack.EMPTY; } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerFurnaceDouble.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerFurnaceDouble.java index a23f79047..7afda6fda 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerFurnaceDouble.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerFurnaceDouble.java @@ -22,7 +22,9 @@ import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Recipe; +import net.minecraft.world.item.crafting.RecipeHolder; import net.minecraft.world.item.crafting.RecipeType; +import net.minecraft.world.item.crafting.SmeltingRecipe; import javax.annotation.Nonnull; import java.util.Objects; @@ -78,12 +80,12 @@ public class ContainerFurnaceDouble extends AbstractContainerMenu { //Other Slots in Inventory excluded else if (slot >= inventoryStart) { // TODO: VALIDATE - Recipe irecipe = this.furnace.getLevel().getRecipeManager().getRecipeFor(RecipeType.SMELTING, new SingleItem(newStack), this.furnace.getLevel()).orElse(null); - if (irecipe == null) { + RecipeHolder recipeHolder = this.furnace.getLevel().getRecipeManager().getRecipeFor(RecipeType.SMELTING, new SingleItem(newStack), this.furnace.getLevel()).orElse(null); + if (recipeHolder == null) { return ItemStack.EMPTY; } - ItemStack recipeOutput = irecipe.getResultItem(player.level().registryAccess()); + ItemStack recipeOutput = recipeHolder.value().getResultItem(player.level().registryAccess()); //Shift from Inventory if (StackUtil.isValid(recipeOutput)) { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/SackContainer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/SackContainer.java index 111521b85..e211f0269 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/SackContainer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/SackContainer.java @@ -27,8 +27,8 @@ import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.inventory.ClickType; import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import javax.annotation.Nonnull; import java.util.UUID; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/Buttons.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/Buttons.java index f0b094011..63035674f 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/Buttons.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/Buttons.java @@ -8,8 +8,8 @@ import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.Button; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; public class Buttons { @OnlyIn(Dist.CLIENT) diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/CrusherScreen.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/CrusherScreen.java index 29df27cdc..2967d1ac6 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/CrusherScreen.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/CrusherScreen.java @@ -20,8 +20,8 @@ import net.minecraft.client.gui.components.Button; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Inventory; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import javax.annotation.Nonnull; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/EnergyDisplay.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/EnergyDisplay.java index 59bf92835..bf023f18a 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/EnergyDisplay.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/EnergyDisplay.java @@ -16,8 +16,8 @@ import de.ellpeck.actuallyadditions.mod.util.AssetUtil; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.network.chat.Component; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import java.text.NumberFormat; import java.util.ArrayList; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/FilterSettingsGui.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/FilterSettingsGui.java index d73a110c8..8dda63a13 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/FilterSettingsGui.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/FilterSettingsGui.java @@ -18,8 +18,8 @@ import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.Renderable; import net.minecraft.network.chat.Component; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/FluidDisplay.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/FluidDisplay.java index 96bc686d2..a053b8f25 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/FluidDisplay.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/FluidDisplay.java @@ -17,12 +17,12 @@ import net.minecraft.client.gui.GuiGraphics; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.material.Fluid; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.client.extensions.common.IClientFluidTypeExtensions; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.IFluidTank; -import net.minecraftforge.fluids.capability.IFluidHandler; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; +import net.neoforged.neoforge.client.extensions.common.IClientFluidTypeExtensions; +import net.neoforged.neoforge.fluids.FluidStack; +import net.neoforged.neoforge.fluids.IFluidTank; +import net.neoforged.neoforge.fluids.capability.IFluidHandler; import javax.annotation.Nonnull; import java.text.NumberFormat; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiBreaker.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiBreaker.java index f59c3e654..3dc28bc51 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiBreaker.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiBreaker.java @@ -18,8 +18,8 @@ import net.minecraft.client.gui.GuiGraphics; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Inventory; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import javax.annotation.Nonnull; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiCanolaPress.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiCanolaPress.java index 995e6cb5c..5d2a5e171 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiCanolaPress.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiCanolaPress.java @@ -18,8 +18,8 @@ import net.minecraft.client.gui.GuiGraphics; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Inventory; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import javax.annotation.Nonnull; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiCoalGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiCoalGenerator.java index f212e25f2..f8e9b4925 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiCoalGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiCoalGenerator.java @@ -18,8 +18,8 @@ import net.minecraft.client.gui.GuiGraphics; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Inventory; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import javax.annotation.Nonnull; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiCoffeeMachine.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiCoffeeMachine.java index 845716070..3ab28200c 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiCoffeeMachine.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiCoffeeMachine.java @@ -21,8 +21,8 @@ import net.minecraft.client.gui.components.Button; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Inventory; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import javax.annotation.Nonnull; import java.util.Collections; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiDirectionalBreaker.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiDirectionalBreaker.java index c5d431a7c..061dcf5bf 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiDirectionalBreaker.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiDirectionalBreaker.java @@ -18,8 +18,8 @@ import net.minecraft.client.gui.GuiGraphics; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Inventory; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import javax.annotation.Nonnull; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiDrill.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiDrill.java index 7f0d1103e..91148a935 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiDrill.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiDrill.java @@ -19,8 +19,8 @@ import net.minecraft.client.resources.language.I18n; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Inventory; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import javax.annotation.Nonnull; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiDropper.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiDropper.java index d8d009973..6b0a9a45e 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiDropper.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiDropper.java @@ -18,8 +18,8 @@ import net.minecraft.client.gui.GuiGraphics; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Inventory; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; @OnlyIn(Dist.CLIENT) diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiEnergizer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiEnergizer.java index 31238a2a3..283823578 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiEnergizer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiEnergizer.java @@ -18,8 +18,8 @@ import net.minecraft.client.gui.GuiGraphics; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Inventory; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import javax.annotation.Nonnull; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiEnervator.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiEnervator.java index 42d026498..6f8998c44 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiEnervator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiEnervator.java @@ -18,8 +18,8 @@ import net.minecraft.client.gui.GuiGraphics; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Inventory; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import javax.annotation.Nonnull; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiFarmer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiFarmer.java index 485bbc420..2be96ba81 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiFarmer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiFarmer.java @@ -18,8 +18,8 @@ import net.minecraft.client.gui.GuiGraphics; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Inventory; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import javax.annotation.Nonnull; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiFeeder.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiFeeder.java index 8158e0515..4e482af8c 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiFeeder.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiFeeder.java @@ -20,8 +20,8 @@ import net.minecraft.client.resources.language.I18n; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Inventory; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import javax.annotation.Nonnull; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiFermentingBarrel.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiFermentingBarrel.java index 6215b8002..2b01d9bad 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiFermentingBarrel.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiFermentingBarrel.java @@ -18,8 +18,8 @@ import net.minecraft.client.gui.GuiGraphics; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Inventory; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import javax.annotation.Nonnull; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiFilter.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiFilter.java index f59b90250..20f263572 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiFilter.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiFilter.java @@ -19,8 +19,8 @@ import net.minecraft.client.resources.language.I18n; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Inventory; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import javax.annotation.Nonnull; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiFireworkBox.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiFireworkBox.java index 0adabe05e..5aac4e906 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiFireworkBox.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiFireworkBox.java @@ -16,8 +16,8 @@ import net.minecraft.client.gui.components.AbstractSliderButton; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.network.chat.Component; import net.minecraft.world.entity.player.Inventory; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; // TODO: FIX ME @OnlyIn(Dist.CLIENT) diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiFluidCollector.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiFluidCollector.java index 7ecaaa477..7504a8d4b 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiFluidCollector.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiFluidCollector.java @@ -18,8 +18,8 @@ import net.minecraft.client.gui.GuiGraphics; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Inventory; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import javax.annotation.Nonnull; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiFurnaceDouble.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiFurnaceDouble.java index 1ab98202f..5204fd855 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiFurnaceDouble.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiFurnaceDouble.java @@ -22,8 +22,8 @@ import net.minecraft.client.gui.components.Button; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Inventory; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import javax.annotation.Nonnull; import java.util.Collections; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiLaserRelayItemWhitelist.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiLaserRelayItemWhitelist.java index fa827ae6d..87e81c860 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiLaserRelayItemWhitelist.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiLaserRelayItemWhitelist.java @@ -21,8 +21,8 @@ import net.minecraft.client.resources.language.I18n; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Inventory; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import javax.annotation.Nonnull; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiMiner.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiMiner.java index 25c27714e..c81ca4774 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiMiner.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiMiner.java @@ -18,8 +18,8 @@ import net.minecraft.client.gui.GuiGraphics; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Inventory; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; @OnlyIn(Dist.CLIENT) diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiOilGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiOilGenerator.java index 6c5026668..c2efdfbe5 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiOilGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiOilGenerator.java @@ -20,8 +20,8 @@ import net.minecraft.client.resources.language.I18n; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Inventory; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import javax.annotation.Nonnull; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiPhantomPlacer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiPhantomPlacer.java index 55b1410f6..bc7289f3f 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiPhantomPlacer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiPhantomPlacer.java @@ -18,8 +18,8 @@ import net.minecraft.client.gui.GuiGraphics; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Inventory; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import javax.annotation.Nonnull; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiRangedCollector.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiRangedCollector.java index 97db97c7f..38caebee4 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiRangedCollector.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiRangedCollector.java @@ -18,8 +18,8 @@ import net.minecraft.client.gui.GuiGraphics; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Inventory; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import javax.annotation.Nonnull; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiSmileyCloud.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiSmileyCloud.java index 485b30b94..3a64b0198 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiSmileyCloud.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiSmileyCloud.java @@ -122,6 +122,6 @@ // compound.putInt("PlayerID", Minecraft.getInstance().player.getEntityId()); // compound.putInt("TextID", textID); // compound.setString("Text", text); -// PacketHandler.THE_NETWORK.sendToServer(new PacketClientToServer(compound, PacketHandler.GUI_STRING_TO_TILE_HANDLER)); +// PacketDistributor.SERVER.noArg().send(new PacketClientToServer(compound, PacketHandler.GUI_STRING_TO_TILE_HANDLER)); // } //} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiXPSolidifier.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiXPSolidifier.java index 929d3bd05..6390fcf2c 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiXPSolidifier.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiXPSolidifier.java @@ -18,8 +18,8 @@ import net.minecraft.client.gui.GuiGraphics; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Inventory; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; @OnlyIn(Dist.CLIENT) diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/SackGui.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/SackGui.java index 3af40510f..3e7a6615e 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/SackGui.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/SackGui.java @@ -56,7 +56,7 @@ public class SackGui extends AAScreen { // data.putInt("ButtonID", button.id); // data.putInt("PlayerID", Minecraft.getInstance().player.getId()); // data.putInt("WorldID", Minecraft.getInstance().level.provider.getDimension()); -// PacketHandler.THE_NETWORK.sendToServer(new PacketClientToServer(data, PacketHandler.GUI_BUTTON_TO_CONTAINER_HANDLER)); +// PacketDistributor.SERVER.noArg().send(new PacketClientToServer(data, PacketHandler.GUI_BUTTON_TO_CONTAINER_HANDLER)); // } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/TexturedButton.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/TexturedButton.java index b5f4b7efc..e3dde93ba 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/TexturedButton.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/TexturedButton.java @@ -17,8 +17,8 @@ import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.Button; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/slot/SlotItemHandlerUnconditioned.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/slot/SlotItemHandlerUnconditioned.java index 8b8f67c53..d9cdc0896 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/slot/SlotItemHandlerUnconditioned.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/slot/SlotItemHandlerUnconditioned.java @@ -13,7 +13,7 @@ package de.ellpeck.actuallyadditions.mod.inventory.slot; import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; -import net.minecraftforge.items.SlotItemHandler; +import net.neoforged.neoforge.items.SlotItemHandler; import javax.annotation.Nonnull; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ActuallyItems.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ActuallyItems.java index 46cbc0c57..d7c247e3f 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ActuallyItems.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ActuallyItems.java @@ -16,15 +16,18 @@ import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.blocks.AABlockItem; import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks; import de.ellpeck.actuallyadditions.mod.items.base.ItemBase; +import de.ellpeck.actuallyadditions.mod.items.base.ItemEnergy; import de.ellpeck.actuallyadditions.mod.items.lens.ItemLens; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Tiers; import net.minecraft.world.item.crafting.RecipeType; -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.capabilities.Capabilities; +import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent; +import net.neoforged.neoforge.registries.DeferredHolder; +import net.neoforged.neoforge.registries.DeferredItem; +import net.neoforged.neoforge.registries.DeferredRegister; import org.jetbrains.annotations.Nullable; import javax.annotation.Nonnull; @@ -32,151 +35,151 @@ import java.util.Set; import java.util.function.Supplier; public final class ActuallyItems { - public static final DeferredRegister ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, ActuallyAdditions.MODID); + public static final DeferredRegister.Items ITEMS = DeferredRegister.createItems(ActuallyAdditions.MODID); // MISC ITEMS - public static final RegistryObject CANOLA = ITEMS.register("canola", ItemBase::new); - public static final RegistryObject COFFEE_CUP = ITEMS.register("coffee_cup", ItemBase::new); - public static final RegistryObject PAPER_CONE = ITEMS.register("paper_cone", ItemBase::new); - public static final RegistryObject DOUGH = ITEMS.register("dough", ItemBase::new); - public static final RegistryObject RING = ITEMS.register("ring", ItemBase::new); - public static final RegistryObject BASIC_COIL = ITEMS.register("basic_coil", ItemBase::new); - public static final RegistryObject ADVANCED_COIL = ITEMS.register("advanced_coil", ItemBase::new); - public static final RegistryObject RICE = ITEMS.register("rice", ItemBase::new); - public static final RegistryObject RICE_DOUGH = ITEMS.register("rice_dough", ItemBase::new); - public static final RegistryObject TINY_COAL = ITEMS.register("tiny_coal", () -> new ItemBase() { + public static final DeferredItem CANOLA = ITEMS.register("canola", () -> new ItemBase()); + public static final DeferredItem COFFEE_CUP = ITEMS.register("coffee_cup", () -> new ItemBase()); + public static final DeferredItem PAPER_CONE = ITEMS.register("paper_cone", () -> new ItemBase()); + public static final DeferredItem DOUGH = ITEMS.register("dough", () -> new ItemBase()); + public static final DeferredItem RING = ITEMS.register("ring", () -> new ItemBase()); + public static final DeferredItem BASIC_COIL = ITEMS.register("basic_coil", () -> new ItemBase()); + public static final DeferredItem ADVANCED_COIL = ITEMS.register("advanced_coil", () -> new ItemBase()); + public static final DeferredItem RICE = ITEMS.register("rice", () -> new ItemBase()); + public static final DeferredItem RICE_DOUGH = ITEMS.register("rice_dough", () -> new ItemBase()); + public static final DeferredItem TINY_COAL = ITEMS.register("tiny_coal", () -> new ItemBase() { @Override public int getBurnTime(ItemStack itemStack, @Nullable RecipeType recipeType) { return 200; } }); - public static final RegistryObject TINY_CHARCOAL = ITEMS.register("tiny_charcoal", () -> new ItemBase() { + public static final DeferredItem TINY_CHARCOAL = ITEMS.register("tiny_charcoal", () -> new ItemBase() { @Override public int getBurnTime(ItemStack itemStack, @Nullable RecipeType recipeType) { return 200; } }); - public static final RegistryObject RICE_SLIMEBALL = ITEMS.register("rice_slimeball", ItemBase::new); - public static final RegistryObject EMPTY_CUP = ITEMS.register("empty_cup", ItemBase::new); - public static final RegistryObject BATS_WING = ITEMS.register("bats_wing", ItemBase::new); - public static final RegistryObject DRILL_CORE = ITEMS.register("drill_core", ItemBase::new); - public static final RegistryObject LENS = ITEMS.register("lens", ItemBase::new); - public static final RegistryObject ENDER_STAR = ITEMS.register("ender_star", () -> new ItemBase() { + public static final DeferredItem RICE_SLIMEBALL = ITEMS.register("rice_slimeball", () -> new ItemBase()); + public static final DeferredItem EMPTY_CUP = ITEMS.register("empty_cup", () -> new ItemBase()); + public static final DeferredItem BATS_WING = ITEMS.register("bats_wing", () -> new ItemBase()); + public static final DeferredItem DRILL_CORE = ITEMS.register("drill_core", () -> new ItemBase()); + public static final DeferredItem LENS = ITEMS.register("lens", () -> new ItemBase()); + public static final DeferredItem ENDER_STAR = ITEMS.register("ender_star", () -> new ItemBase() { @Override public boolean isFoil(@Nonnull ItemStack pStack) { return true; } }); - public static final RegistryObject CRYSTALLIZED_CANOLA_SEED = ITEMS.register("crystallized_canola_seed", () -> new CanolaSeed(false)); - public static final RegistryObject EMPOWERED_CANOLA_SEED = ITEMS.register("empowered_canola_seed", () -> new CanolaSeed(true)); + public static final DeferredItem CRYSTALLIZED_CANOLA_SEED = ITEMS.register("crystallized_canola_seed", () -> new CanolaSeed(false)); + public static final DeferredItem EMPOWERED_CANOLA_SEED = ITEMS.register("empowered_canola_seed", () -> new CanolaSeed(true)); // SHARDS - public static final RegistryObject RESTONIA_CRYSTAL_SHARD = ITEMS.register("restonia_crystal_shard", ItemBase::new); - public static final RegistryObject PALIS_CRYSTAL_SHARD = ITEMS.register("palis_crystal_shard", ItemBase::new); - public static final RegistryObject DIAMATINE_CRYSTAL_SHARD = ITEMS.register("diamatine_crystal_shard", ItemBase::new); - public static final RegistryObject VOID_CRYSTAL_SHARD = ITEMS.register("void_crystal_shard", ItemBase::new); - public static final RegistryObject EMERADIC_CRYSTAL_SHARD = ITEMS.register("emeradic_crystal_shard", ItemBase::new); - public static final RegistryObject ENORI_CRYSTAL_SHARD = ITEMS.register("enori_crystal_shard", ItemBase::new); + public static final DeferredItem RESTONIA_CRYSTAL_SHARD = ITEMS.register("restonia_crystal_shard", () -> new ItemBase()); + public static final DeferredItem PALIS_CRYSTAL_SHARD = ITEMS.register("palis_crystal_shard", () -> new ItemBase()); + public static final DeferredItem DIAMATINE_CRYSTAL_SHARD = ITEMS.register("diamatine_crystal_shard", () -> new ItemBase()); + public static final DeferredItem VOID_CRYSTAL_SHARD = ITEMS.register("void_crystal_shard", () -> new ItemBase()); + public static final DeferredItem EMERADIC_CRYSTAL_SHARD = ITEMS.register("emeradic_crystal_shard", () -> new ItemBase()); + public static final DeferredItem ENORI_CRYSTAL_SHARD = ITEMS.register("enori_crystal_shard", () -> new ItemBase()); // CRYSTALS - public static final RegistryObject RESTONIA_CRYSTAL = ITEMS.register("restonia_crystal", ItemCrystal::new); - public static final RegistryObject PALIS_CRYSTAL = ITEMS.register("palis_crystal", ItemCrystal::new); - public static final RegistryObject DIAMATINE_CRYSTAL = ITEMS.register("diamatine_crystal", ItemCrystal::new); - public static final RegistryObject VOID_CRYSTAL = ITEMS.register("void_crystal", ItemCrystal::new); - public static final RegistryObject EMERADIC_CRYSTAL = ITEMS.register("emeradic_crystal", ItemCrystal::new); - public static final RegistryObject ENORI_CRYSTAL = ITEMS.register("enori_crystal", ItemCrystal::new); + public static final DeferredItem RESTONIA_CRYSTAL = ITEMS.register("restonia_crystal", () -> new ItemCrystal()); + public static final DeferredItem PALIS_CRYSTAL = ITEMS.register("palis_crystal", () -> new ItemCrystal()); + public static final DeferredItem DIAMATINE_CRYSTAL = ITEMS.register("diamatine_crystal", () -> new ItemCrystal()); + public static final DeferredItem VOID_CRYSTAL = ITEMS.register("void_crystal", () -> new ItemCrystal()); + public static final DeferredItem EMERADIC_CRYSTAL = ITEMS.register("emeradic_crystal", () -> new ItemCrystal()); + public static final DeferredItem ENORI_CRYSTAL = ITEMS.register("enori_crystal", () -> new ItemCrystal()); - public static final RegistryObject EMPOWERED_RESTONIA_CRYSTAL = ITEMS.register("empowered_restonia_crystal", () -> new ItemCrystal(true)); - public static final RegistryObject EMPOWERED_PALIS_CRYSTAL = ITEMS.register("empowered_palis_crystal", () -> new ItemCrystal(true)); - public static final RegistryObject EMPOWERED_DIAMATINE_CRYSTAL = ITEMS.register("empowered_diamatine_crystal", () -> new ItemCrystal(true)); - public static final RegistryObject EMPOWERED_VOID_CRYSTAL = ITEMS.register("empowered_void_crystal", () -> new ItemCrystal(true)); - public static final RegistryObject EMPOWERED_EMERADIC_CRYSTAL = ITEMS.register("empowered_emeradic_crystal", () -> new ItemCrystal(true)); - public static final RegistryObject EMPOWERED_ENORI_CRYSTAL = ITEMS.register("empowered_enori_crystal", () -> new ItemCrystal(true)); + public static final DeferredItem EMPOWERED_RESTONIA_CRYSTAL = ITEMS.register("empowered_restonia_crystal", () -> new ItemCrystal(true)); + public static final DeferredItem EMPOWERED_PALIS_CRYSTAL = ITEMS.register("empowered_palis_crystal", () -> new ItemCrystal(true)); + public static final DeferredItem EMPOWERED_DIAMATINE_CRYSTAL = ITEMS.register("empowered_diamatine_crystal", () -> new ItemCrystal(true)); + public static final DeferredItem EMPOWERED_VOID_CRYSTAL = ITEMS.register("empowered_void_crystal", () -> new ItemCrystal(true)); + public static final DeferredItem EMPOWERED_EMERADIC_CRYSTAL = ITEMS.register("empowered_emeradic_crystal", () -> new ItemCrystal(true)); + public static final DeferredItem EMPOWERED_ENORI_CRYSTAL = ITEMS.register("empowered_enori_crystal", () -> new ItemCrystal(true)); // BLACK QUARTZ - public static final RegistryObject BLACK_QUARTZ = ITEMS.register("black_quartz", ItemBase::new); + public static final DeferredItem BLACK_QUARTZ = ITEMS.register("black_quartz", () -> new ItemBase()); - public static final RegistryObject ENGINEERS_GOGGLES_ADVANCED = ITEMS.register("engineers_goggles_advanced", () -> new ItemEngineerGoggles(true)); - public static final RegistryObject ENGINEERS_GOGGLES = ITEMS.register("engineers_goggles", () -> new ItemEngineerGoggles(false)); - public static final RegistryObject LASER_UPGRADE_RANGE = ITEMS.register("laser_upgrade_range", ItemLaserRelayUpgrade::new); - public static final RegistryObject LASER_UPGRADE_INVISIBILITY = ITEMS.register("laser_upgrade_invisibility", ItemLaserRelayUpgrade::new); + public static final DeferredItem ENGINEERS_GOGGLES_ADVANCED = ITEMS.register("engineers_goggles_advanced", () -> new ItemEngineerGoggles(true)); + public static final DeferredItem ENGINEERS_GOGGLES = ITEMS.register("engineers_goggles", () -> new ItemEngineerGoggles(false)); + public static final DeferredItem LASER_UPGRADE_RANGE = ITEMS.register("laser_upgrade_range", ItemLaserRelayUpgrade::new); + public static final DeferredItem LASER_UPGRADE_INVISIBILITY = ITEMS.register("laser_upgrade_invisibility", ItemLaserRelayUpgrade::new); public static final Supplier HANDHELD_FILLER = ITEMS.register("handheld_filler", ItemFillingWand::new); - public static final RegistryObject TRAVELERS_SACK = ITEMS.register("travelers_sack", () -> new Sack(false)); - public static final RegistryObject VOID_SACK = ITEMS.register("void_sack", () -> new Sack(true)); - public static final RegistryObject WORM = ITEMS.register("worm", Worm::new); - public static final RegistryObject PLAYER_PROBE = ITEMS.register("player_probe", ItemPlayerProbe::new); - public static final RegistryObject FILTER = ITEMS.register("filter", ItemFilter::new); - public static final RegistryObject WATER_BOWL = ITEMS.register("water_bowl", ItemWaterBowl::new); - public static final RegistryObject CRATE_KEEPER = ITEMS.register("crate_keeper", () -> new ItemGeneric(defaultProps().stacksTo(1))); - public static final RegistryObject LENS_OF_COLOR = ITEMS.register("lens_of_color", () -> new ItemLens(ActuallyAdditionsAPI.lensColor)); - public static final RegistryObject LENS_OF_DETONATION = ITEMS.register("lens_of_detonation", () -> new ItemLens(ActuallyAdditionsAPI.lensDetonation)); - public static final RegistryObject LENS_OF_CERTAIN_DEATH = ITEMS.register("lens_of_certain_death", () -> new ItemLens(ActuallyAdditionsAPI.lensDeath)); - public static final RegistryObject LENS_OF_THE_KILLER = ITEMS.register("lens_of_the_killer", () -> new ItemLens(ActuallyAdditionsAPI.lensEvenMoarDeath)); - public static final RegistryObject LENS_OF_DISENCHANTING = ITEMS.register("lens_of_disenchanting", () -> new ItemLens(ActuallyAdditionsAPI.lensDisenchanting)); - public static final RegistryObject LENS_OF_THE_MINER = ITEMS.register("lens_of_the_miner", () -> new ItemLens(ActuallyAdditionsAPI.lensMining)); - public static final RegistryObject LASER_WRENCH = ITEMS.register("laser_wrench", ItemLaserWrench::new); - // public static final RegistryObject itemChestToCrateUpgrade = ITEMS.register("", new ItemChestToCrateUpgrade("chest_to_crate_upgrade", TileEntityChest.class, InitBlocks.blockGiantChest.getDefaultState())); - // public static final RegistryObject itemSmallToMediumCrateUpgrade = ITEMS.register("", new ItemChestToCrateUpgrade("small_to_medium_crate_upgrade", TileEntityGiantChest.class, InitBlocks.blockGiantChestMedium.getDefaultState())); - // public static final RegistryObject itemMediumToLargeCrateUpgrade = ITEMS.register("", new ItemChestToCrateUpgrade("medium_to_large_crate_upgrade", TileEntityGiantChestMedium.class, InitBlocks.blockGiantChestLarge.getDefaultState())); - public static final RegistryObject ITEM_BOOKLET = ITEMS.register("booklet", ItemBooklet::new); - public static final RegistryObject RING_OF_GROWTH = ITEMS.register("ring_of_growth", ItemGrowthRing::new); - public static final RegistryObject RING_OF_MAGNETIZING = ITEMS.register("ring_of_magnetizing", ItemMagnetRing::new); - public static final RegistryObject TELEPORT_STAFF = ITEMS.register("teleport_staff", ItemTeleportStaff::new); - public static final RegistryObject WINGS_OF_THE_BATS = ITEMS.register("wings_of_the_bats", ItemWingsOfTheBats::new); + public static final DeferredItem TRAVELERS_SACK = ITEMS.register("travelers_sack", () -> new Sack(false)); + public static final DeferredItem VOID_SACK = ITEMS.register("void_sack", () -> new Sack(true)); + public static final DeferredItem WORM = ITEMS.register("worm", Worm::new); + public static final DeferredItem PLAYER_PROBE = ITEMS.register("player_probe", ItemPlayerProbe::new); + public static final DeferredItem FILTER = ITEMS.register("filter", ItemFilter::new); + public static final DeferredItem WATER_BOWL = ITEMS.register("water_bowl", ItemWaterBowl::new); + public static final DeferredItem CRATE_KEEPER = ITEMS.register("crate_keeper", () -> new ItemGeneric(defaultProps().stacksTo(1))); + public static final DeferredItem LENS_OF_COLOR = ITEMS.register("lens_of_color", () -> new ItemLens(ActuallyAdditionsAPI.lensColor)); + public static final DeferredItem LENS_OF_DETONATION = ITEMS.register("lens_of_detonation", () -> new ItemLens(ActuallyAdditionsAPI.lensDetonation)); + public static final DeferredItem LENS_OF_CERTAIN_DEATH = ITEMS.register("lens_of_certain_death", () -> new ItemLens(ActuallyAdditionsAPI.lensDeath)); + public static final DeferredItem LENS_OF_THE_KILLER = ITEMS.register("lens_of_the_killer", () -> new ItemLens(ActuallyAdditionsAPI.lensEvenMoarDeath)); + public static final DeferredItem LENS_OF_DISENCHANTING = ITEMS.register("lens_of_disenchanting", () -> new ItemLens(ActuallyAdditionsAPI.lensDisenchanting)); + public static final DeferredItem LENS_OF_THE_MINER = ITEMS.register("lens_of_the_miner", () -> new ItemLens(ActuallyAdditionsAPI.lensMining)); + public static final DeferredItem LASER_WRENCH = ITEMS.register("laser_wrench", ItemLaserWrench::new); + // public static final DeferredItem itemChestToCrateUpgrade = ITEMS.register("", new ItemChestToCrateUpgrade("chest_to_crate_upgrade", TileEntityChest.class, InitBlocks.blockGiantChest.getDefaultState())); + // public static final DeferredItem itemSmallToMediumCrateUpgrade = ITEMS.register("", new ItemChestToCrateUpgrade("small_to_medium_crate_upgrade", TileEntityGiantChest.class, InitBlocks.blockGiantChestMedium.getDefaultState())); + // public static final DeferredItem itemMediumToLargeCrateUpgrade = ITEMS.register("", new ItemChestToCrateUpgrade("medium_to_large_crate_upgrade", TileEntityGiantChestMedium.class, InitBlocks.blockGiantChestLarge.getDefaultState())); + public static final DeferredItem ITEM_BOOKLET = ITEMS.register("booklet", ItemBooklet::new); + public static final DeferredItem RING_OF_GROWTH = ITEMS.register("ring_of_growth", ItemGrowthRing::new); + public static final DeferredItem RING_OF_MAGNETIZING = ITEMS.register("ring_of_magnetizing", ItemMagnetRing::new); + public static final DeferredItem TELEPORT_STAFF = ITEMS.register("teleport_staff", ItemTeleportStaff::new); + public static final DeferredItem WINGS_OF_THE_BATS = ITEMS.register("wings_of_the_bats", ItemWingsOfTheBats::new); - public static final RegistryObject DRILL_MAIN = ITEMS.register("drill_light_blue", DrillItem::new); - public static final RegistryObject DRILL_BLACK = ITEMS.register("drill_black", DrillItem::new); - public static final RegistryObject DRILL_BLUE = ITEMS.register("drill_blue", DrillItem::new); - public static final RegistryObject DRILL_BROWN = ITEMS.register("drill_brown", DrillItem::new); - public static final RegistryObject DRILL_CYAN = ITEMS.register("drill_cyan", DrillItem::new); - public static final RegistryObject DRILL_GRAY = ITEMS.register("drill_gray", DrillItem::new); - public static final RegistryObject DRILL_GREEN = ITEMS.register("drill_green", DrillItem::new); - public static final RegistryObject DRILL_LIGHT_GRAY = ITEMS.register("drill_light_gray", DrillItem::new); - public static final RegistryObject DRILL_LIME = ITEMS.register("drill_lime", DrillItem::new); - public static final RegistryObject DRILL_MAGENTA = ITEMS.register("drill_magenta", DrillItem::new); - public static final RegistryObject DRILL_ORANGE = ITEMS.register("drill_orange", DrillItem::new); - public static final RegistryObject DRILL_PINK = ITEMS.register("drill_pink", DrillItem::new); - public static final RegistryObject DRILL_PURPLE = ITEMS.register("drill_purple", DrillItem::new); - public static final RegistryObject DRILL_RED = ITEMS.register("drill_red", DrillItem::new); - public static final RegistryObject DRILL_WHITE = ITEMS.register("drill_white", DrillItem::new); - public static final RegistryObject DRILL_YELLOW = ITEMS.register("drill_yellow", DrillItem::new); + public static final DeferredItem DRILL_MAIN = ITEMS.register("drill_light_blue", DrillItem::new); + public static final DeferredItem DRILL_BLACK = ITEMS.register("drill_black", DrillItem::new); + public static final DeferredItem DRILL_BLUE = ITEMS.register("drill_blue", DrillItem::new); + public static final DeferredItem DRILL_BROWN = ITEMS.register("drill_brown", DrillItem::new); + public static final DeferredItem DRILL_CYAN = ITEMS.register("drill_cyan", DrillItem::new); + public static final DeferredItem DRILL_GRAY = ITEMS.register("drill_gray", DrillItem::new); + public static final DeferredItem DRILL_GREEN = ITEMS.register("drill_green", DrillItem::new); + public static final DeferredItem DRILL_LIGHT_GRAY = ITEMS.register("drill_light_gray", DrillItem::new); + public static final DeferredItem DRILL_LIME = ITEMS.register("drill_lime", DrillItem::new); + public static final DeferredItem DRILL_MAGENTA = ITEMS.register("drill_magenta", DrillItem::new); + public static final DeferredItem DRILL_ORANGE = ITEMS.register("drill_orange", DrillItem::new); + public static final DeferredItem DRILL_PINK = ITEMS.register("drill_pink", DrillItem::new); + public static final DeferredItem DRILL_PURPLE = ITEMS.register("drill_purple", DrillItem::new); + public static final DeferredItem DRILL_RED = ITEMS.register("drill_red", DrillItem::new); + public static final DeferredItem DRILL_WHITE = ITEMS.register("drill_white", DrillItem::new); + public static final DeferredItem DRILL_YELLOW = ITEMS.register("drill_yellow", DrillItem::new); - public static final RegistryObject SINGLE_BATTERY = ITEMS.register("single_battery", () -> new ItemBattery(200000, 1000)); - public static final RegistryObject DOUBLE_BATTERY = ITEMS.register("double_battery", () -> new ItemBattery(350000, 5000)); - public static final RegistryObject TRIPLE_BATTERY = ITEMS.register("triple_battery", () -> new ItemBattery(600000, 10000)); - public static final RegistryObject QUADRUPLE_BATTERY = ITEMS.register("quadruple_battery", () -> new ItemBattery(1000000, 30000)); - public static final RegistryObject QUINTUPLE_BATTERY = ITEMS.register("quintuple_battery", () -> new ItemBattery(2000000, 100000)); - public static final RegistryObject DRILL_UPGRADE_SPEED = ITEMS.register("drill_upgrade_speed", () -> new ItemDrillUpgrade(ItemDrillUpgrade.UpgradeType.SPEED)); - public static final RegistryObject DRILL_UPGRADE_SPEED_II = ITEMS.register("drill_upgrade_speed_ii", () -> new ItemDrillUpgrade(ItemDrillUpgrade.UpgradeType.SPEED_II)); - public static final RegistryObject DRILL_UPGRADE_SPEED_III = ITEMS.register("drill_upgrade_speed_iii", () -> new ItemDrillUpgrade(ItemDrillUpgrade.UpgradeType.SPEED_III)); - public static final RegistryObject DRILL_UPGRADE_SILK_TOUCH = ITEMS.register("drill_upgrade_silk_touch", () -> new ItemDrillUpgrade(ItemDrillUpgrade.UpgradeType.SILK_TOUCH)); - public static final RegistryObject DRILL_UPGRADE_FORTUNE = ITEMS.register("drill_upgrade_fortune", () -> new ItemDrillUpgrade(ItemDrillUpgrade.UpgradeType.FORTUNE)); - public static final RegistryObject DRILL_UPGRADE_FORTUNE_II = ITEMS.register("drill_upgrade_fortune_ii", () -> new ItemDrillUpgrade(ItemDrillUpgrade.UpgradeType.FORTUNE_II)); - public static final RegistryObject DRILL_UPGRADE_THREE_BY_THREE = ITEMS.register("drill_upgrade_three_by_three", () -> new ItemDrillUpgrade(ItemDrillUpgrade.UpgradeType.THREE_BY_THREE)); - public static final RegistryObject DRILL_UPGRADE_FIVE_BY_FIVE = ITEMS.register("drill_upgrade_five_by_five", () -> new ItemDrillUpgrade(ItemDrillUpgrade.UpgradeType.FIVE_BY_FIVE)); - public static final RegistryObject DRILL_UPGRADE_BLOCK_PLACING = ITEMS.register("drill_upgrade_block_placing", () -> new ItemDrillUpgrade(ItemDrillUpgrade.UpgradeType.PLACER)); - public static final RegistryObject PHANTOM_CONNECTOR = ITEMS.register("phantom_connector", ItemPhantomConnector::new); - //public static final RegistryObject FOOD = ITEMS.register("food", ItemBase::new); //just... food? //TODO - public static final RegistryObject CRAFTER_ON_A_STICK = ITEMS.register("crafter_on_a_stick", ItemCrafterOnAStick::new); - //public static final RegistryObject DUST = ITEMS.register("dust", ItemDust::new); //TODO flatten - public static final RegistryObject SOLIDIFIED_EXPERIENCE = ITEMS.register("solidified_experience", ItemSolidifiedExperience::new); - public static final RegistryObject LEAF_BLOWER = ITEMS.register("leaf_blower", () -> new ItemLeafBlower(false)); - public static final RegistryObject ADVANCED_LEAF_BLOWER = ITEMS.register("advanced_leaf_blower", () -> new ItemLeafBlower(true)); + public static final DeferredItem SINGLE_BATTERY = ITEMS.register("single_battery", () -> new ItemBattery(200000, 1000)); + public static final DeferredItem DOUBLE_BATTERY = ITEMS.register("double_battery", () -> new ItemBattery(350000, 5000)); + public static final DeferredItem TRIPLE_BATTERY = ITEMS.register("triple_battery", () -> new ItemBattery(600000, 10000)); + public static final DeferredItem QUADRUPLE_BATTERY = ITEMS.register("quadruple_battery", () -> new ItemBattery(1000000, 30000)); + public static final DeferredItem QUINTUPLE_BATTERY = ITEMS.register("quintuple_battery", () -> new ItemBattery(2000000, 100000)); + public static final DeferredItem DRILL_UPGRADE_SPEED = ITEMS.register("drill_upgrade_speed", () -> new ItemDrillUpgrade(ItemDrillUpgrade.UpgradeType.SPEED)); + public static final DeferredItem DRILL_UPGRADE_SPEED_II = ITEMS.register("drill_upgrade_speed_ii", () -> new ItemDrillUpgrade(ItemDrillUpgrade.UpgradeType.SPEED_II)); + public static final DeferredItem DRILL_UPGRADE_SPEED_III = ITEMS.register("drill_upgrade_speed_iii", () -> new ItemDrillUpgrade(ItemDrillUpgrade.UpgradeType.SPEED_III)); + public static final DeferredItem DRILL_UPGRADE_SILK_TOUCH = ITEMS.register("drill_upgrade_silk_touch", () -> new ItemDrillUpgrade(ItemDrillUpgrade.UpgradeType.SILK_TOUCH)); + public static final DeferredItem DRILL_UPGRADE_FORTUNE = ITEMS.register("drill_upgrade_fortune", () -> new ItemDrillUpgrade(ItemDrillUpgrade.UpgradeType.FORTUNE)); + public static final DeferredItem DRILL_UPGRADE_FORTUNE_II = ITEMS.register("drill_upgrade_fortune_ii", () -> new ItemDrillUpgrade(ItemDrillUpgrade.UpgradeType.FORTUNE_II)); + public static final DeferredItem DRILL_UPGRADE_THREE_BY_THREE = ITEMS.register("drill_upgrade_three_by_three", () -> new ItemDrillUpgrade(ItemDrillUpgrade.UpgradeType.THREE_BY_THREE)); + public static final DeferredItem DRILL_UPGRADE_FIVE_BY_FIVE = ITEMS.register("drill_upgrade_five_by_five", () -> new ItemDrillUpgrade(ItemDrillUpgrade.UpgradeType.FIVE_BY_FIVE)); + public static final DeferredItem DRILL_UPGRADE_BLOCK_PLACING = ITEMS.register("drill_upgrade_block_placing", () -> new ItemDrillUpgrade(ItemDrillUpgrade.UpgradeType.PLACER)); + public static final DeferredItem PHANTOM_CONNECTOR = ITEMS.register("phantom_connector", ItemPhantomConnector::new); + //public static final DeferredItem FOOD = ITEMS.register("food", () -> new ItemBase()); //just... food? //TODO + public static final DeferredItem CRAFTER_ON_A_STICK = ITEMS.register("crafter_on_a_stick", ItemCrafterOnAStick::new); + //public static final DeferredItem DUST = ITEMS.register("dust", ItemDust::new); //TODO flatten + public static final DeferredItem SOLIDIFIED_EXPERIENCE = ITEMS.register("solidified_experience", ItemSolidifiedExperience::new); + public static final DeferredItem LEAF_BLOWER = ITEMS.register("leaf_blower", () -> new ItemLeafBlower(false)); + public static final DeferredItem ADVANCED_LEAF_BLOWER = ITEMS.register("advanced_leaf_blower", () -> new ItemLeafBlower(true)); - public static final RegistryObject COFFEE_BEANS = ITEMS.register("coffee_beans", () -> new AABlockItem.AASeedItem(ActuallyBlocks.COFFEE.get(), ActuallyItems.defaultProps())); + public static final DeferredItem COFFEE_BEANS = ITEMS.register("coffee_beans", () -> new AABlockItem.AASeedItem(ActuallyBlocks.COFFEE.get(), ActuallyItems.defaultProps())); - public static final RegistryObject RICE_SEEDS = ITEMS.register("rice_seeds", () -> new AABlockItem.AASeedItem(ActuallyBlocks.RICE.get(), ActuallyItems.defaultProps())); //() -> new ItemSeed("seedRice", ActuallyBlocks.RICE.get(), FOOD.get(), TheFoods.RICE.ordinal())); - public static final RegistryObject CANOLA_SEEDS = ITEMS.register("canola_seeds", () -> new AABlockItem.AASeedItem(ActuallyBlocks.CANOLA.get(), ActuallyItems.defaultProps())); //() -> new ItemFoodSeed("seedCanola", ActuallyBlocks.CANOLA, itemMisc, 0, 1, 0.01F, 10).setPotionEffect(new PotionEffect(MobEffects.NAUSEA, 1000, 0), 0.2F)); - public static final RegistryObject FLAX_SEEDS = ITEMS.register("flax_seeds", () -> new AABlockItem.AASeedItem(ActuallyBlocks.FLAX.get(), ActuallyItems.defaultProps())); //() -> new ItemSeed("seedFlax", ActuallyBlocks.FLAX, Items.STRING, 0)); + public static final DeferredItem RICE_SEEDS = ITEMS.register("rice_seeds", () -> new AABlockItem.AASeedItem(ActuallyBlocks.RICE.get(), ActuallyItems.defaultProps())); //() -> new ItemSeed("seedRice", ActuallyBlocks.RICE.get(), FOOD.get(), TheFoods.RICE.ordinal())); + public static final DeferredItem CANOLA_SEEDS = ITEMS.register("canola_seeds", () -> new AABlockItem.AASeedItem(ActuallyBlocks.CANOLA.get(), ActuallyItems.defaultProps())); //() -> new ItemFoodSeed("seedCanola", ActuallyBlocks.CANOLA, itemMisc, 0, 1, 0.01F, 10).setPotionEffect(new PotionEffect(MobEffects.NAUSEA, 1000, 0), 0.2F)); + public static final DeferredItem FLAX_SEEDS = ITEMS.register("flax_seeds", () -> new AABlockItem.AASeedItem(ActuallyBlocks.FLAX.get(), ActuallyItems.defaultProps())); //() -> new ItemSeed("seedFlax", ActuallyBlocks.FLAX, Items.STRING, 0)); // TOOLS & ARMOR - public static final RegistryObject WOODEN_AIOT = ITEMS.register("wooden_aiot", () -> new AllInOneTool(Tiers.WOOD)); - public static final RegistryObject STONE_AIOT = ITEMS.register("stone_aiot", () -> new AllInOneTool(Tiers.STONE)); - public static final RegistryObject IRON_AIOT = ITEMS.register("iron_aiot", () -> new AllInOneTool(Tiers.IRON)); - public static final RegistryObject GOLD_AIOT = ITEMS.register("gold_aiot", () -> new AllInOneTool(Tiers.GOLD)); - public static final RegistryObject DIAMOND_AIOT = ITEMS.register("diamond_aiot", () -> new AllInOneTool(Tiers.DIAMOND)); - public static final RegistryObject NETHERITE_AIOT = ITEMS.register("netherite_aiot", () -> new AllInOneTool(Tiers.NETHERITE)); + public static final DeferredItem WOODEN_AIOT = ITEMS.register("wooden_aiot", () -> new AllInOneTool(Tiers.WOOD)); + public static final DeferredItem STONE_AIOT = ITEMS.register("stone_aiot", () -> new AllInOneTool(Tiers.STONE)); + public static final DeferredItem IRON_AIOT = ITEMS.register("iron_aiot", () -> new AllInOneTool(Tiers.IRON)); + public static final DeferredItem GOLD_AIOT = ITEMS.register("gold_aiot", () -> new AllInOneTool(Tiers.GOLD)); + public static final DeferredItem DIAMOND_AIOT = ITEMS.register("diamond_aiot", () -> new AllInOneTool(Tiers.DIAMOND)); + public static final DeferredItem NETHERITE_AIOT = ITEMS.register("netherite_aiot", () -> new AllInOneTool(Tiers.NETHERITE)); public static final Set> SIMPLE_ITEMS = ImmutableSet.of( // Crystals @@ -220,5 +223,14 @@ public final class ActuallyItems { public static void init(IEventBus evt) { ITEMS.register(evt); + evt.addListener(ActuallyItems::registerCapabilities); + } + + public static void registerCapabilities(RegisterCapabilitiesEvent event) { + for(DeferredHolder holder : ITEMS.getEntries()) { + if(holder.get() instanceof ItemEnergy energyItem) { + //TODO: Register the CustomEnergyStorage capability to the ItemEnergy extending items + } + } } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/AllInOneTool.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/AllInOneTool.java index 1528cc87b..93ecc96e9 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/AllInOneTool.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/AllInOneTool.java @@ -9,8 +9,8 @@ import net.minecraft.world.item.Items; import net.minecraft.world.item.Tier; import net.minecraft.world.item.context.UseOnContext; import net.minecraft.world.item.enchantment.Enchantment; -import net.minecraftforge.common.ToolAction; -import net.minecraftforge.common.ToolActions; +import net.neoforged.neoforge.common.ToolAction; +import net.neoforged.neoforge.common.ToolActions; public class AllInOneTool extends DiggerItem implements IActuallyItem { private final Tier tier; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/DrillItem.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/DrillItem.java index 3df6394d7..1915e6e2a 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/DrillItem.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/DrillItem.java @@ -24,6 +24,7 @@ import de.ellpeck.actuallyadditions.mod.util.StackUtil; import de.ellpeck.actuallyadditions.mod.util.WorldUtil; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; @@ -49,13 +50,13 @@ import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.HitResult; -import net.minecraftforge.common.ForgeHooks; -import net.minecraftforge.common.Tags; -import net.minecraftforge.common.ToolAction; -import net.minecraftforge.common.ToolActions; -import net.minecraftforge.items.IItemHandler; -import net.minecraftforge.items.IItemHandlerModifiable; -import net.minecraftforge.registries.ForgeRegistries; +import net.neoforged.neoforge.common.CommonHooks; +import net.neoforged.neoforge.common.Tags; +import net.neoforged.neoforge.common.TierSortingRegistry; +import net.neoforged.neoforge.common.ToolAction; +import net.neoforged.neoforge.common.ToolActions; +import net.neoforged.neoforge.items.IItemHandler; +import net.neoforged.neoforge.items.IItemHandlerModifiable; public class DrillItem extends ItemEnergy { @@ -76,8 +77,8 @@ public class DrillItem extends ItemEnergy { @Override public boolean isCorrectToolForDrops(BlockState pBlock) { Tier tier = Tiers.NETHERITE; //Use Nettherite as the tier as it has the same harvest level as the drill - if (net.minecraftforge.common.TierSortingRegistry.isTierSorted(tier)) { - return net.minecraftforge.common.TierSortingRegistry.isCorrectTierForDrops(tier, pBlock) && pBlock.is(ActuallyTags.Blocks.MINEABLE_WITH_DRILL); + if (TierSortingRegistry.isTierSorted(tier)) { + return TierSortingRegistry.isCorrectTierForDrops(tier, pBlock) && pBlock.is(ActuallyTags.Blocks.MINEABLE_WITH_DRILL); } if (HARVEST_LEVEL < 3 && pBlock.is(BlockTags.NEEDS_DIAMOND_TOOL)) { return false; @@ -475,7 +476,7 @@ public class DrillItem extends ItemEnergy { Block block = state.getBlock(); float hardness = state.getDestroySpeed(world, pos); - boolean canHarvest = (ForgeHooks.isCorrectToolForDrops(state, player) || this.isCorrectToolForDrops(stack, state)) && (!isExtra || this.getDestroySpeed(stack, world.getBlockState(pos)) > 1.0F); + boolean canHarvest = (CommonHooks.isCorrectToolForDrops(state, player) || this.isCorrectToolForDrops(stack, state)) && (!isExtra || this.getDestroySpeed(stack, world.getBlockState(pos)) > 1.0F); if (hardness >= 0.0F && (!isExtra || canHarvest && !state.hasBlockEntity())) { if (!player.isCreative()) { this.extractEnergyInternal(stack, use, false); @@ -488,7 +489,7 @@ public class DrillItem extends ItemEnergy { private boolean hasExtraWhitelist(Block block) { if (block != null) { - ResourceLocation location = ForgeRegistries.BLOCKS.getKey(block); + ResourceLocation location = BuiltInRegistries.BLOCK.getKey(block); if (location != null) { String name = location.toString(); if (name != null) { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemBattery.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemBattery.java index 7d0871831..c03d3f805 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemBattery.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemBattery.java @@ -20,15 +20,15 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.level.Level; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.common.capabilities.ForgeCapabilities; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.energy.IEnergyStorage; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; +import net.neoforged.neoforge.capabilities.Capabilities; +import net.neoforged.neoforge.energy.IEnergyStorage; import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.List; +import java.util.Optional; public class ItemBattery extends ItemEnergy { @@ -47,7 +47,7 @@ public class ItemBattery extends ItemEnergy { for (int i = 0; i < player.getInventory().getContainerSize(); i++) { ItemStack slot = player.getInventory().getItem(i); if (!slot.isEmpty() && slot.getCount() == 1) { - LazyOptional energy = slot.getCapability(ForgeCapabilities.ENERGY); + Optional energy = Optional.ofNullable(slot.getCapability(Capabilities.EnergyStorage.ITEM)); energy.ifPresent(cap -> { int extractable = this.extractEnergy(stack, Integer.MAX_VALUE, true); int received = cap.receiveEnergy(extractable, false); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemBooklet.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemBooklet.java index 2cc70eb80..fd7c45bfe 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemBooklet.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemBooklet.java @@ -16,7 +16,7 @@ import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.blocks.IHudDisplay; import de.ellpeck.actuallyadditions.mod.items.base.ItemBase; import net.minecraft.ChatFormatting; -import net.minecraft.advancements.Advancement; +import net.minecraft.advancements.AdvancementHolder; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.network.chat.Component; @@ -33,8 +33,8 @@ import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.item.context.UseOnContext; import net.minecraft.world.level.Level; import net.minecraft.world.phys.HitResult; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import javax.annotation.Nullable; import java.util.List; @@ -72,7 +72,7 @@ public class ItemBooklet extends ItemBase implements IHudDisplay { ServerPlayer serverPlayer = (ServerPlayer) player; PlayerAdvancements advancements = serverPlayer.getAdvancements(); ServerAdvancementManager manager = player.getServer().getAdvancements(); - Advancement advancement = manager.getAdvancement(new ResourceLocation(ActuallyAdditions.MODID, "root")); + AdvancementHolder advancement = manager.get(new ResourceLocation(ActuallyAdditions.MODID, "root")); if (advancement != null && !advancements.getOrStartProgress(advancement).isDone()) { advancements.award(advancement, "right_click"); } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemCoffee.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemCoffee.java index 4327b72ba..6f15830df 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemCoffee.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemCoffee.java @@ -26,9 +26,9 @@ import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.item.enchantment.Enchantment; import net.minecraft.world.level.Level; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.fml.ModList; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; +import net.neoforged.fml.ModList; import javax.annotation.Nullable; import java.util.List; @@ -101,11 +101,11 @@ public class ItemCoffee extends ItemFoodBase { // return EnumAction.DRINK; //} - @Nullable - @Override - public CompoundTag getShareTag(ItemStack stack) { - return super.getShareTag(stack); - } +// @Nullable +// @Override +// public CompoundTag getShareTag(ItemStack stack) { +// return super.getShareTag(stack); +// } @OnlyIn(Dist.CLIENT) @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemCrafterOnAStick.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemCrafterOnAStick.java index d6c66f096..6c3aef5c4 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemCrafterOnAStick.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemCrafterOnAStick.java @@ -12,7 +12,6 @@ package de.ellpeck.actuallyadditions.mod.items; import de.ellpeck.actuallyadditions.mod.items.base.ItemBase; import net.minecraft.network.chat.Component; -import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResultHolder; @@ -21,7 +20,6 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.CraftingMenu; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; -import net.minecraftforge.network.NetworkHooks; import javax.annotation.Nonnull; @@ -36,7 +34,7 @@ public class ItemCrafterOnAStick extends ItemBase { @Override public InteractionResultHolder use(Level world, @Nonnull Player player, @Nonnull InteractionHand hand) { if (!world.isClientSide) { - NetworkHooks.openScreen((ServerPlayer) player, new SimpleMenuProvider((windowId, playerInventory, playerEntity) -> new CraftingMenu(windowId, playerInventory), CONTAINER_TITLE)); + player.openMenu(new SimpleMenuProvider((windowId, playerInventory, playerEntity) -> new CraftingMenu(windowId, playerInventory), CONTAINER_TITLE)); } return new InteractionResultHolder<>(InteractionResult.SUCCESS, player.getItemInHand(hand)); } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemEngineerGoggles.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemEngineerGoggles.java index b4c020413..30ee2227f 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemEngineerGoggles.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemEngineerGoggles.java @@ -20,12 +20,12 @@ import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.phys.AABB; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.event.TickEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.DistExecutor; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.loading.FMLEnvironment; +import net.neoforged.neoforge.common.NeoForge; +import net.neoforged.neoforge.event.TickEvent; import java.util.List; import java.util.Set; @@ -40,7 +40,9 @@ public class ItemEngineerGoggles extends ItemArmorAA implements IGoggles { super(ArmorMaterials.GOGGLES, Type.HELMET, ActuallyItems.defaultProps().setNoRepair().durability(0)); this.displayMobs = displayMobs; - DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> MinecraftForge.EVENT_BUS.register(this)); + if (FMLEnvironment.dist.isClient()) { + NeoForge.EVENT_BUS.register(this); + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemFillingWand.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemFillingWand.java index a760b6d31..cf4e7d308 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemFillingWand.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemFillingWand.java @@ -33,8 +33,8 @@ import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.HitResult; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import javax.annotation.Nullable; import java.util.List; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemFilter.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemFilter.java index 17abdbbf7..137f40cc0 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemFilter.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemFilter.java @@ -15,7 +15,6 @@ import de.ellpeck.actuallyadditions.mod.items.base.ItemBase; import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA; import de.ellpeck.actuallyadditions.mod.util.StackUtil; import net.minecraft.network.chat.Component; -import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.SimpleMenuProvider; @@ -23,9 +22,8 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.level.Level; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.network.NetworkHooks; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import javax.annotation.Nullable; import java.util.List; @@ -39,7 +37,7 @@ public class ItemFilter extends ItemBase { @Override public InteractionResultHolder use(Level world, Player player, InteractionHand hand) { if (!world.isClientSide && hand == InteractionHand.MAIN_HAND) { - NetworkHooks.openScreen((ServerPlayer) player, new SimpleMenuProvider((windowId, inv, playerEnt) -> new ContainerFilter(windowId, inv), Component.empty())); + player.openMenu(new SimpleMenuProvider((windowId, inv, playerEnt) -> new ContainerFilter(windowId, inv), Component.empty())); // player.openGui(ActuallyAdditions.INSTANCE, GuiHandler.GuiTypes.FILTER.ordinal(), world, (int) player.posX, (int) player.posY, (int) player.posZ); } return InteractionResultHolder.pass(player.getItemInHand(hand)); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemGrowthRing.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemGrowthRing.java index 0f880f69c..e3c969042 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemGrowthRing.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemGrowthRing.java @@ -23,7 +23,7 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.BonemealableBlock; import net.minecraft.world.level.block.GrassBlock; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.common.IPlantable; +import net.neoforged.neoforge.common.IPlantable; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemLaserWrench.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemLaserWrench.java index 2ddc2ff90..1c2820c9d 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemLaserWrench.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemLaserWrench.java @@ -24,8 +24,8 @@ import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.item.context.UseOnContext; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import java.util.List; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemLeafBlower.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemLeafBlower.java index da7ed3160..8b477e4fb 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemLeafBlower.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemLeafBlower.java @@ -29,7 +29,7 @@ import net.minecraft.world.level.block.BushBlock; import net.minecraft.world.level.block.LeavesBlock; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.common.IForgeShearable; +import net.neoforged.neoforge.common.IShearable; import javax.annotation.Nonnull; import java.util.ArrayList; @@ -104,7 +104,7 @@ public class ItemLeafBlower extends ItemBase implements IDisplayStandItem { BlockPos pos = new BlockPos(x + reachX, y + reachY, z + reachZ); Block block = world.getBlockState(pos).getBlock(); - if ((block instanceof BushBlock || block instanceof IForgeShearable) && (this.isAdvanced || !(block instanceof LeavesBlock))) { + if ((block instanceof BushBlock || block instanceof IShearable) && (this.isAdvanced || !(block instanceof LeavesBlock))) { breakPositions.add(pos); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemPhantomConnector.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemPhantomConnector.java index 2f0ce9478..b01cf910e 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemPhantomConnector.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemPhantomConnector.java @@ -27,8 +27,8 @@ import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.item.context.UseOnContext; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import javax.annotation.Nullable; import java.util.List; @@ -106,11 +106,11 @@ public class ItemPhantomConnector extends ItemBase { return InteractionResult.SUCCESS; } - @Nullable - @Override - public CompoundTag getShareTag(ItemStack stack) { - return new CompoundTag(); - } +// @Nullable +// @Override +// public CompoundTag getShareTag(ItemStack stack) { +// return new CompoundTag(); +// } @OnlyIn(Dist.CLIENT) @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemPlayerProbe.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemPlayerProbe.java index 93e0a8a92..d7d987acc 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemPlayerProbe.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemPlayerProbe.java @@ -26,8 +26,8 @@ import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.item.context.UseOnContext; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import javax.annotation.Nullable; import java.util.List; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemShovelAA.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemShovelAA.java index 210e1da5d..5914074b6 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemShovelAA.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemShovelAA.java @@ -29,7 +29,7 @@ import java.util.Set; public class ItemShovelAA extends ItemToolAA { - private static final Set EFFECTIVE_ON = Sets.newHashSet(Blocks.CLAY, Blocks.DIRT, Blocks.FARMLAND, Blocks.GRASS, Blocks.GRAVEL, Blocks.MYCELIUM, Blocks.SAND, Blocks.SNOW, Blocks.SNOW_BLOCK, Blocks.SOUL_SAND, Blocks.DIRT_PATH); + private static final Set EFFECTIVE_ON = Sets.newHashSet(Blocks.CLAY, Blocks.DIRT, Blocks.FARMLAND, Blocks.GRASS_BLOCK, Blocks.GRAVEL, Blocks.MYCELIUM, Blocks.SAND, Blocks.SNOW, Blocks.SNOW_BLOCK, Blocks.SOUL_SAND, Blocks.DIRT_PATH); public ItemShovelAA(float p_i48512_1_, float p_i48512_2_, Tier p_i48512_3_, TagKey p_i48512_4_, Properties p_i48512_5_, String name, ItemStack repairItem, TagKey repairTag) { super(p_i48512_1_, p_i48512_2_, p_i48512_3_, p_i48512_4_, p_i48512_5_, name, repairItem, repairTag); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemSolidifiedExperience.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemSolidifiedExperience.java index 54ab6d4b4..00ff90094 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemSolidifiedExperience.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemSolidifiedExperience.java @@ -19,7 +19,7 @@ import net.minecraft.world.entity.ExperienceOrb; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; -import net.minecraftforge.common.util.FakePlayer; +import net.neoforged.neoforge.common.util.FakePlayer; public class ItemSolidifiedExperience extends ItemBase { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemWaterBowl.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemWaterBowl.java index bbd60814c..2373b4921 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemWaterBowl.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemWaterBowl.java @@ -34,9 +34,9 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.HitResult; -import net.minecraftforge.event.ForgeEventFactory; -import net.minecraftforge.event.entity.player.PlayerInteractEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.neoforge.event.EventHooks; +import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent; public class ItemWaterBowl extends ItemBase { @@ -56,7 +56,7 @@ public class ItemWaterBowl extends ItemBase { } BlockHitResult trace = (BlockHitResult) rayTrace; - InteractionResultHolder result = ForgeEventFactory.onBucketUse(event.getEntity(), event.getLevel(), event.getItemStack(), trace); + InteractionResultHolder result = EventHooks.onBucketUse(event.getEntity(), event.getLevel(), event.getItemStack(), trace); if (result == null) { if (event.getEntity().mayUseItemAt(trace.getBlockPos().relative(trace.getDirection()), trace.getDirection(), event.getItemStack())) { BlockState state = event.getLevel().getBlockState(trace.getBlockPos()); @@ -92,7 +92,7 @@ public class ItemWaterBowl extends ItemBase { ItemStack stack = player.getItemInHand(hand); HitResult trace = WorldUtil.getNearestBlockWithDefaultReachDistance(world, player); - InteractionResultHolder result = ForgeEventFactory.onBucketUse(player, world, stack, trace); + InteractionResultHolder result = EventHooks.onBucketUse(player, world, stack, trace); if (result != null) { return result; } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemWingsOfTheBats.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemWingsOfTheBats.java index 9d0fee2e9..f19e046e2 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemWingsOfTheBats.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemWingsOfTheBats.java @@ -25,9 +25,9 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.SwordItem; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.event.entity.living.LivingDropsEvent; -import net.minecraftforge.event.entity.living.LivingEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.neoforge.event.entity.living.LivingDropsEvent; +import net.neoforged.neoforge.event.entity.living.LivingEvent; public class ItemWingsOfTheBats extends ItemBase { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/Sack.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/Sack.java index fae3f4e7f..4f81e49d5 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/Sack.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/Sack.java @@ -16,6 +16,7 @@ import de.ellpeck.actuallyadditions.mod.sack.SackData; import de.ellpeck.actuallyadditions.mod.sack.SackManager; import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA; import de.ellpeck.actuallyadditions.mod.util.StackUtil; +import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.InteractionHand; @@ -27,9 +28,9 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.context.UseOnContext; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraftforge.common.capabilities.ForgeCapabilities; -import net.minecraftforge.network.NetworkHooks; +import net.neoforged.neoforge.capabilities.Capabilities; +import java.util.Optional; import java.util.UUID; public class Sack extends ItemBase { @@ -44,12 +45,14 @@ public class Sack extends ItemBase { public InteractionResult useOn(UseOnContext context) { ItemStack stack = context.getPlayer().getItemInHand(context.getHand()); if (!this.isVoid) { - BlockEntity tile = context.getLevel().getBlockEntity(context.getClickedPos()); + Level level = context.getLevel(); + BlockPos clickedPos = context.getClickedPos(); + BlockEntity tile = level.getBlockEntity(clickedPos); if (tile != null) { if (!context.getLevel().isClientSide) { ItemStackHandlerAA inv = new ItemStackHandlerAA(28); - boolean changed = tile.getCapability(ForgeCapabilities.ITEM_HANDLER, context.getClickedFace()) + boolean changed = Optional.ofNullable(level.getCapability(Capabilities.ItemHandler.BLOCK, clickedPos, context.getClickedFace())) .map(cap -> { boolean localChanged = false; DrillItem.loadSlotsFromNBT(inv, stack); @@ -99,7 +102,7 @@ public class Sack extends ItemBase { data.updateAccessRecords(player.getName().getString(), System.currentTimeMillis()); - NetworkHooks.openScreen((ServerPlayer) player, new SimpleMenuProvider((id, inv, entity) -> + player.openMenu(new SimpleMenuProvider((id, inv, entity) -> new SackContainer(id, inv, uuid, data.getSpecialHandler()), sackStack.getHoverName()), (buffer -> buffer.writeUUID(uuid))); } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/Worm.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/Worm.java index b6fbcff70..d4cbfe8ed 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/Worm.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/Worm.java @@ -23,9 +23,9 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.AABB; -import net.minecraftforge.common.ToolActions; -import net.minecraftforge.event.level.BlockEvent; -import net.minecraftforge.eventbus.api.Event; +import net.neoforged.bus.api.Event; +import net.neoforged.neoforge.common.ToolActions; +import net.neoforged.neoforge.event.level.BlockEvent; import java.util.List; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/base/ItemEnergy.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/base/ItemEnergy.java index 06ac10d04..aa93d7e53 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/base/ItemEnergy.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/base/ItemEnergy.java @@ -12,25 +12,19 @@ package de.ellpeck.actuallyadditions.mod.items.base; import de.ellpeck.actuallyadditions.mod.items.ActuallyItems; import de.ellpeck.actuallyadditions.mod.tile.CustomEnergyStorage; -import net.minecraft.core.Direction; -import net.minecraft.nbt.CompoundTag; 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 net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.common.capabilities.ForgeCapabilities; -import net.minecraftforge.common.capabilities.ICapabilityProvider; -import net.minecraftforge.common.capabilities.ICapabilitySerializable; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.energy.IEnergyStorage; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; +import net.neoforged.neoforge.capabilities.Capabilities; +import net.neoforged.neoforge.energy.IEnergyStorage; -import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.text.NumberFormat; import java.util.List; +import java.util.Optional; public abstract class ItemEnergy extends ItemBase { @@ -98,7 +92,7 @@ public abstract class ItemEnergy extends ItemBase { } public void setEnergy(ItemStack stack, int energy) { - stack.getCapability(ForgeCapabilities.ENERGY, null).ifPresent(cap -> { + Optional.ofNullable(stack.getCapability(Capabilities.EnergyStorage.ITEM, null)).ifPresent(cap -> { if (cap instanceof CustomEnergyStorage) { ((CustomEnergyStorage) cap).setEnergyStored(energy); } @@ -107,13 +101,13 @@ public abstract class ItemEnergy extends ItemBase { @Deprecated public int receiveEnergyInternal(ItemStack stack, int maxReceive, boolean simulate) { - return stack.getCapability(ForgeCapabilities.ENERGY) + return Optional.ofNullable(stack.getCapability(Capabilities.EnergyStorage.ITEM, null)) .map(cap -> ((CustomEnergyStorage) cap).receiveEnergyInternal(maxReceive, simulate)) .orElse(0); } public int extractEnergyInternal(ItemStack stack, int maxExtract, boolean simulate) { - return stack.getCapability(ForgeCapabilities.ENERGY) + return Optional.ofNullable(stack.getCapability(Capabilities.EnergyStorage.ITEM, null)) .map(cap -> cap instanceof CustomEnergyStorage ? ((CustomEnergyStorage) cap).extractEnergyInternal(maxExtract, simulate) : 0) @@ -122,68 +116,68 @@ public abstract class ItemEnergy extends ItemBase { @Deprecated public int receiveEnergy(ItemStack stack, int maxReceive, boolean simulate) { - return stack.getCapability(ForgeCapabilities.ENERGY) + return Optional.ofNullable(stack.getCapability(Capabilities.EnergyStorage.ITEM, null)) .map(cap -> cap.receiveEnergy(maxReceive, simulate)) .orElse(0); } public int extractEnergy(ItemStack stack, int maxExtract, boolean simulate) { - return stack.getCapability(ForgeCapabilities.ENERGY) + return Optional.ofNullable(stack.getCapability(Capabilities.EnergyStorage.ITEM, null)) .map(cap -> cap.extractEnergy(maxExtract, simulate)) .orElse(0); } public int getEnergyStored(ItemStack stack) { - return stack.getCapability(ForgeCapabilities.ENERGY, null) + return Optional.ofNullable(stack.getCapability(Capabilities.EnergyStorage.ITEM, null)) .map(IEnergyStorage::getEnergyStored) .orElse(0); } public int getMaxEnergyStored(ItemStack stack) { - return stack.getCapability(ForgeCapabilities.ENERGY, null) + return Optional.ofNullable(stack.getCapability(Capabilities.EnergyStorage.ITEM, null)) .map(IEnergyStorage::getMaxEnergyStored) .orElse(0); } - @Override - public ICapabilityProvider initCapabilities(ItemStack stack, CompoundTag nbt) { - return new EnergyCapabilityProvider(stack, this); - } +// @Override TODO: Register Energy cap/attachment +// public ICapabilityProvider initCapabilities(ItemStack stack, CompoundTag nbt) { +// return new EnergyCapabilityProvider(stack, this); +// } - private static class EnergyCapabilityProvider implements ICapabilitySerializable { - - public final CustomEnergyStorage storage; - private final LazyOptional energyCapability; - - private final ItemStack stack; - - public EnergyCapabilityProvider(ItemStack stack, ItemEnergy item) { - this.storage = new CustomEnergyStorage(item.maxPower, item.transfer, item.transfer); - this.energyCapability = LazyOptional.of(() -> this.storage); - this.stack = stack; - } - - @Nonnull - @Override - public LazyOptional getCapability(@Nonnull Capability cap, @Nullable Direction side) { - if (cap == ForgeCapabilities.ENERGY) { - return this.energyCapability.cast(); - } - return LazyOptional.empty(); - } - - @Override - public CompoundTag serializeNBT() { - if (this.storage.isDirty()) - stack.getOrCreateTag().putInt("Energy", this.storage.getEnergyStored()); - this.storage.clearDirty(); - return new CompoundTag(); - } - - @Override - public void deserializeNBT(CompoundTag nbt) { - if (stack.getOrCreateTag().contains("Energy")) - this.storage.setEnergyStored(stack.getOrCreateTag().getInt("Energy")); - } - } +// private static class EnergyCapabilityProvider implements ICapabilitySerializable { +// +// public final CustomEnergyStorage storage; +// private final LazyOptional energyCapability; +// +// private final ItemStack stack; +// +// public EnergyCapabilityProvider(ItemStack stack, ItemEnergy item) { +// this.storage = new CustomEnergyStorage(item.maxPower, item.transfer, item.transfer); +// this.energyCapability = LazyOptional.of(() -> this.storage); +// this.stack = stack; +// } +// +// @Nonnull +// @Override +// public LazyOptional getCapability(@Nonnull Capability cap, @Nullable Direction side) { +// if (cap == Capabilities.ENERGY) { +// return this.energyCapability.cast(); +// } +// return LazyOptional.empty(); +// } +// +// @Override +// public CompoundTag serializeNBT() { +// if (this.storage.isDirty()) +// stack.getOrCreateTag().putInt("Energy", this.storage.getEnergyStored()); +// this.storage.clearDirty(); +// return new CompoundTag(); +// } +// +// @Override +// public void deserializeNBT(CompoundTag nbt) { +// if (stack.getOrCreateTag().contains("Energy")) +// this.storage.setEnergyStored(stack.getOrCreateTag().getInt("Energy")); +// } +// } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/LensKiller.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/LensKiller.java index 2112fefef..0179a62be 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/LensKiller.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/LensKiller.java @@ -13,7 +13,7 @@ package de.ellpeck.actuallyadditions.mod.items.lens; import de.ellpeck.actuallyadditions.api.internal.IAtomicReconstructor; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.LivingEntity; -import net.minecraftforge.common.util.FakePlayerFactory; +import net.neoforged.neoforge.common.util.FakePlayerFactory; public class LensKiller extends LensDeath { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/LensMining.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/LensMining.java index 5bd727d8d..e88a74acc 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/LensMining.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/LensMining.java @@ -19,6 +19,7 @@ import net.minecraft.core.BlockPos; import net.minecraft.util.random.WeightedRandom; import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.RecipeHolder; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; @@ -83,9 +84,9 @@ public class LensMining extends Lens { Block hitBlock = hitState.getBlock(); ItemStack item = new ItemStack(hitBlock.asItem()); - for(MiningLensRecipe r:ActuallyAdditionsAPI.MINING_LENS_RECIPES) { - if (r.matches(item)) - ores.add(r); + for(RecipeHolder r:ActuallyAdditionsAPI.MINING_LENS_RECIPES) { + if (r.value().matches(item)) + ores.add(r.value()); } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/jei/FermentingCategory.java b/src/main/java/de/ellpeck/actuallyadditions/mod/jei/FermentingCategory.java index 0c590febd..2789e183a 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/jei/FermentingCategory.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/jei/FermentingCategory.java @@ -2,7 +2,6 @@ package de.ellpeck.actuallyadditions.mod.jei; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.crafting.FermentingRecipe; -import de.ellpeck.actuallyadditions.mod.inventory.gui.FluidDisplay; import de.ellpeck.actuallyadditions.mod.util.AssetUtil; import mezz.jei.api.gui.builder.IRecipeLayoutBuilder; import mezz.jei.api.gui.drawable.IDrawable; @@ -16,8 +15,7 @@ import mezz.jei.api.recipe.category.IRecipeCategory; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.FluidType; +import net.neoforged.neoforge.fluids.FluidStack; public class FermentingCategory implements IRecipeCategory { private final IDrawableStatic background; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/jei/JEIActuallyAdditionsPlugin.java b/src/main/java/de/ellpeck/actuallyadditions/mod/jei/JEIActuallyAdditionsPlugin.java index 29053df08..ae494d86b 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/jei/JEIActuallyAdditionsPlugin.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/jei/JEIActuallyAdditionsPlugin.java @@ -28,6 +28,7 @@ import mezz.jei.api.registration.IRecipeRegistration; import net.minecraft.client.Minecraft; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.RecipeHolder; import net.minecraft.world.level.Level; @JeiPlugin @@ -46,9 +47,9 @@ public class JEIActuallyAdditionsPlugin implements IModPlugin { public void registerCategories(IRecipeCategoryRegistration registry) { IJeiHelpers helpers = registry.getJeiHelpers(); - registry.addRecipeCategories(new FermentingCategory(helpers.getGuiHelper())); //TODO: re-enable after refactor jei compat - registry.addRecipeCategories(new LaserRecipeCategory(helpers.getGuiHelper())); //TODO: re-enable after refactor jei compat - registry.addRecipeCategories(new EmpowererRecipeCategory(helpers.getGuiHelper())); //TODO: re-enable after refactor jei compat + registry.addRecipeCategories(new FermentingCategory(helpers.getGuiHelper())); + registry.addRecipeCategories(new LaserRecipeCategory(helpers.getGuiHelper())); + registry.addRecipeCategories(new EmpowererRecipeCategory(helpers.getGuiHelper())); //registry.addRecipeCategories(new CoffeeMachineRecipeCategory(helpers.getGuiHelper()), new CompostRecipeCategory(helpers.getGuiHelper()), new CrusherRecipeCategory(helpers.getGuiHelper()), new ReconstructorRecipeCategory(helpers.getGuiHelper()), new EmpowererRecipeCategory(helpers.getGuiHelper()), new BookletRecipeCategory(helpers.getGuiHelper())); } @@ -56,9 +57,9 @@ public class JEIActuallyAdditionsPlugin implements IModPlugin { @Override public void registerRecipeCatalysts(IRecipeCatalystRegistration registry) { registry.addRecipeCatalyst(new ItemStack(ActuallyItems.CRAFTER_ON_A_STICK.get()), RecipeTypes.CRAFTING); - registry.addRecipeCatalyst(new ItemStack(ActuallyBlocks.FERMENTING_BARREL.getItem()), FERMENTING); //TODO: re-enable after refactor jei compat - registry.addRecipeCatalyst(new ItemStack(ActuallyBlocks.ATOMIC_RECONSTRUCTOR.getItem()), LASER); //TODO: re-enable after refactor jei compat - registry.addRecipeCatalyst(new ItemStack(ActuallyBlocks.EMPOWERER.getItem()), EMPOWERER); //TODO: re-enable after refactor jei compat + registry.addRecipeCatalyst(new ItemStack(ActuallyBlocks.FERMENTING_BARREL.getItem()), FERMENTING); + registry.addRecipeCatalyst(new ItemStack(ActuallyBlocks.ATOMIC_RECONSTRUCTOR.getItem()), LASER); + registry.addRecipeCatalyst(new ItemStack(ActuallyBlocks.EMPOWERER.getItem()), EMPOWERER); // registry.addRecipeCatalyst(new ItemStack(ActuallyBlocks.blockFurnaceDouble.get()), VanillaRecipeCategoryUid.SMELTING); // registry.addRecipeCatalyst(new ItemStack(ActuallyBlocks.blockGrinder.get()), CrusherRecipeCategory.NAME); @@ -74,9 +75,9 @@ public class JEIActuallyAdditionsPlugin implements IModPlugin { public void registerRecipes(IRecipeRegistration registry) { Level level = Minecraft.getInstance().level; - registry.addRecipes(FERMENTING, level.getRecipeManager().getAllRecipesFor(ActuallyRecipes.Types.FERMENTING.get())); //TODO: re-enable after refactor jei compat - registry.addRecipes(LASER, level.getRecipeManager().getAllRecipesFor(ActuallyRecipes.Types.LASER.get())); //TODO: re-enable after refactor jei compat - registry.addRecipes(EMPOWERER, level.getRecipeManager().getAllRecipesFor(ActuallyRecipes.Types.EMPOWERING.get())); //TODO: re-enable after refactor jei compat + registry.addRecipes(FERMENTING, level.getRecipeManager().getAllRecipesFor(ActuallyRecipes.Types.FERMENTING.get()).stream().map(RecipeHolder::value).toList()); + registry.addRecipes(LASER, level.getRecipeManager().getAllRecipesFor(ActuallyRecipes.Types.LASER.get()).stream().map(RecipeHolder::value).toList()); + registry.addRecipes(EMPOWERER, level.getRecipeManager().getAllRecipesFor(ActuallyRecipes.Types.EMPOWERING.get()).stream().map(RecipeHolder::value).toList()); //registry.addRecipes(ActuallyAdditionsAPI.BOOKLET_PAGES_WITH_ITEM_OR_FLUID_DATA, BookletRecipeCategory.NAME); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/material/ArmorMaterials.java b/src/main/java/de/ellpeck/actuallyadditions/mod/material/ArmorMaterials.java index 878527c21..b25c3830e 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/material/ArmorMaterials.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/material/ArmorMaterials.java @@ -9,8 +9,8 @@ import net.minecraft.util.LazyLoadedValue; import net.minecraft.world.item.ArmorItem; import net.minecraft.world.item.ArmorMaterial; import net.minecraft.world.item.crafting.Ingredient; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import java.util.EnumMap; import java.util.function.Supplier; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/material/ToolMaterials.java b/src/main/java/de/ellpeck/actuallyadditions/mod/material/ToolMaterials.java index b3ee70b63..80853fdb2 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/material/ToolMaterials.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/material/ToolMaterials.java @@ -7,8 +7,8 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.Tier; import net.minecraft.world.item.Tiers; import net.minecraft.world.item.crafting.Ingredient; -import net.minecraftforge.common.ForgeTier; -import net.minecraftforge.common.TierSortingRegistry; +import net.neoforged.neoforge.common.SimpleTier; +import net.neoforged.neoforge.common.TierSortingRegistry; import java.util.List; @@ -16,11 +16,11 @@ import java.util.List; * todo: review to ensure all values act as intended */ public class ToolMaterials { - public static final Tier BLACK_QUARTZ = TierSortingRegistry.registerTier(new ForgeTier(2, 280, 6.5f, 2.0f, 10, ActuallyTags.Blocks.NEEDS_BLACK_QUARTZ_TOOL, () -> Ingredient.of(ActuallyItems.BLACK_QUARTZ.get())), new ResourceLocation(ActuallyAdditions.MODID, "black_quartz"), List.of(Tiers.IRON), List.of(Tiers.DIAMOND)); - public static final Tier RESTONIA = TierSortingRegistry.registerTier(new ForgeTier(2, 300, 7.0f, 2.25f, 12, ActuallyTags.Blocks.NEEDS_RESTONIA_TOOL, () -> Ingredient.of(ActuallyItems.RESTONIA_CRYSTAL.get())), new ResourceLocation(ActuallyAdditions.MODID, "restonia"), List.of(Tiers.IRON), List.of(Tiers.DIAMOND)); - public static final Tier PALIS = TierSortingRegistry.registerTier(new ForgeTier(2, 300, 7.0f, 2.25f, 12, ActuallyTags.Blocks.NEEDS_PALIS_TOOL, () -> Ingredient.of(ActuallyItems.PALIS_CRYSTAL.get())), new ResourceLocation(ActuallyAdditions.MODID, "palis"), List.of(Tiers.IRON), List.of(Tiers.DIAMOND)); - public static final Tier DIAMATINE = TierSortingRegistry.registerTier(new ForgeTier(3, 1600, 9.0f, 4.0f, 14, ActuallyTags.Blocks.NEEDS_DIAMATINE_TOOL, () -> Ingredient.of(ActuallyItems.DIAMATINE_CRYSTAL.get())), new ResourceLocation(ActuallyAdditions.MODID, "diamatine"), List.of(Tiers.DIAMOND), List.of(Tiers.NETHERITE)); - public static final Tier VOID = TierSortingRegistry.registerTier(new ForgeTier(2, 280, 6.0f, 2.0f, 8, ActuallyTags.Blocks.NEEDS_VOID_TOOL, () -> Ingredient.of(ActuallyItems.VOID_CRYSTAL.get())), new ResourceLocation(ActuallyAdditions.MODID, "void"), List.of(Tiers.IRON), List.of(Tiers.DIAMOND)); - public static final Tier EMERADIC = TierSortingRegistry.registerTier(new ForgeTier(4, 2200, 9.5f, 5.55f, 18, ActuallyTags.Blocks.NEEDS_EMERADIC_TOOL, () -> Ingredient.of(ActuallyItems.EMERADIC_CRYSTAL.get())), new ResourceLocation(ActuallyAdditions.MODID, "emeradic"), List.of(Tiers.NETHERITE), List.of()); - public static final Tier ENORI = TierSortingRegistry.registerTier(new ForgeTier(2, 280, 6.25f, 6.25f, 15, ActuallyTags.Blocks.NEEDS_ENORI_TOOL, () -> Ingredient.of(ActuallyItems.ENORI_CRYSTAL.get())), new ResourceLocation(ActuallyAdditions.MODID, "enori"), List.of(Tiers.IRON), List.of(Tiers.DIAMOND)); + public static final Tier BLACK_QUARTZ = TierSortingRegistry.registerTier(new SimpleTier(2, 280, 6.5f, 2.0f, 10, ActuallyTags.Blocks.NEEDS_BLACK_QUARTZ_TOOL, () -> Ingredient.of(ActuallyItems.BLACK_QUARTZ.get())), new ResourceLocation(ActuallyAdditions.MODID, "black_quartz"), List.of(Tiers.IRON), List.of(Tiers.DIAMOND)); + public static final Tier RESTONIA = TierSortingRegistry.registerTier(new SimpleTier(2, 300, 7.0f, 2.25f, 12, ActuallyTags.Blocks.NEEDS_RESTONIA_TOOL, () -> Ingredient.of(ActuallyItems.RESTONIA_CRYSTAL.get())), new ResourceLocation(ActuallyAdditions.MODID, "restonia"), List.of(Tiers.IRON), List.of(Tiers.DIAMOND)); + public static final Tier PALIS = TierSortingRegistry.registerTier(new SimpleTier(2, 300, 7.0f, 2.25f, 12, ActuallyTags.Blocks.NEEDS_PALIS_TOOL, () -> Ingredient.of(ActuallyItems.PALIS_CRYSTAL.get())), new ResourceLocation(ActuallyAdditions.MODID, "palis"), List.of(Tiers.IRON), List.of(Tiers.DIAMOND)); + public static final Tier DIAMATINE = TierSortingRegistry.registerTier(new SimpleTier(3, 1600, 9.0f, 4.0f, 14, ActuallyTags.Blocks.NEEDS_DIAMATINE_TOOL, () -> Ingredient.of(ActuallyItems.DIAMATINE_CRYSTAL.get())), new ResourceLocation(ActuallyAdditions.MODID, "diamatine"), List.of(Tiers.DIAMOND), List.of(Tiers.NETHERITE)); + public static final Tier VOID = TierSortingRegistry.registerTier(new SimpleTier(2, 280, 6.0f, 2.0f, 8, ActuallyTags.Blocks.NEEDS_VOID_TOOL, () -> Ingredient.of(ActuallyItems.VOID_CRYSTAL.get())), new ResourceLocation(ActuallyAdditions.MODID, "void"), List.of(Tiers.IRON), List.of(Tiers.DIAMOND)); + public static final Tier EMERADIC = TierSortingRegistry.registerTier(new SimpleTier(4, 2200, 9.5f, 5.55f, 18, ActuallyTags.Blocks.NEEDS_EMERADIC_TOOL, () -> Ingredient.of(ActuallyItems.EMERADIC_CRYSTAL.get())), new ResourceLocation(ActuallyAdditions.MODID, "emeradic"), List.of(Tiers.NETHERITE), List.of()); + public static final Tier ENORI = TierSortingRegistry.registerTier(new SimpleTier(2, 280, 6.25f, 6.25f, 15, ActuallyTags.Blocks.NEEDS_ENORI_TOOL, () -> Ingredient.of(ActuallyItems.ENORI_CRYSTAL.get())), new ResourceLocation(ActuallyAdditions.MODID, "enori"), List.of(Tiers.IRON), List.of(Tiers.DIAMOND)); } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/misc/DispenserHandlerFertilize.java b/src/main/java/de/ellpeck/actuallyadditions/mod/misc/DispenserHandlerFertilize.java index d727f9ae2..940871789 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/misc/DispenserHandlerFertilize.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/misc/DispenserHandlerFertilize.java @@ -11,8 +11,8 @@ package de.ellpeck.actuallyadditions.mod.misc; import net.minecraft.core.BlockPos; -import net.minecraft.core.BlockSource; import net.minecraft.core.Direction; +import net.minecraft.core.dispenser.BlockSource; import net.minecraft.core.dispenser.DefaultDispenseItemBehavior; import net.minecraft.world.item.BoneMealItem; import net.minecraft.world.item.ItemStack; @@ -23,11 +23,11 @@ public class DispenserHandlerFertilize extends DefaultDispenseItemBehavior { @Override public ItemStack execute(BlockSource source, ItemStack stack) { - Direction facing = source.getBlockState().getValue(BlockStateProperties.FACING); - BlockPos pos = source.getPos().relative(facing); + Direction facing = source.state().getValue(BlockStateProperties.FACING); + BlockPos pos = source.pos().relative(facing); - if (BoneMealItem.growCrop(stack, source.getLevel(), pos)) { - source.getLevel().levelEvent(2005, pos, 0); + if (BoneMealItem.growCrop(stack, source.level(), pos)) { + source.level().levelEvent(2005, pos, 0); } return stack; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/misc/apiimpl/MethodHandler.java b/src/main/java/de/ellpeck/actuallyadditions/mod/misc/apiimpl/MethodHandler.java index 4e657c424..b0f56557e 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/misc/apiimpl/MethodHandler.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/misc/apiimpl/MethodHandler.java @@ -15,18 +15,21 @@ import de.ellpeck.actuallyadditions.api.internal.IMethodHandler; import de.ellpeck.actuallyadditions.api.lens.Lens; import de.ellpeck.actuallyadditions.api.recipe.CoffeeIngredient; import de.ellpeck.actuallyadditions.mod.blocks.BlockLaserRelay; +import de.ellpeck.actuallyadditions.mod.crafting.ColorChangeRecipe; import de.ellpeck.actuallyadditions.mod.crafting.LaserRecipe; import de.ellpeck.actuallyadditions.mod.tile.TileEntityAtomicReconstructor; import de.ellpeck.actuallyadditions.mod.util.StackUtil; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.Vec3i; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.nbt.CompoundTag; import net.minecraft.world.effect.MobEffect; import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.RecipeHolder; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; @@ -116,7 +119,7 @@ public class MethodHandler implements IMethodHandler { int counter = tag.getInt("Counter"); while (counter > 0) { CompoundTag compound = (CompoundTag) tag.get(counter + ""); - MobEffectInstance effect = new MobEffectInstance(MobEffect.byId(compound.getInt("ID")), compound.getInt("Duration"), compound.getByte("Amplifier")); + MobEffectInstance effect = new MobEffectInstance(BuiltInRegistries.MOB_EFFECT.byId(compound.getInt("ID")), compound.getInt("Duration"), compound.getByte("Amplifier")); effects.add(effect); counter--; } @@ -157,14 +160,15 @@ public class MethodHandler implements IMethodHandler { if (state.getBlock() instanceof BlockLaserRelay) { continue; } - Optional recipe = LaserRecipe.getRecipeForStack(new ItemStack(state.getBlock())); - if (recipe.isPresent() && tile.getEnergy() >= recipe.get().getEnergy()) { - ItemStack output = recipe.get().getResultItem(tile.getWorldObject().registryAccess()).copy(); + Optional> holder = LaserRecipe.getRecipeForStack(new ItemStack(state.getBlock())); + if (holder.isPresent() && tile.getEnergy() >= holder.get().value().getEnergy()) { + LaserRecipe recipe = holder.get().value(); + ItemStack output = recipe.getResultItem(tile.getWorldObject().registryAccess()).copy(); if (!output.isEmpty()) { tile.getWorldObject().levelEvent(2001, pos, Block.getId(state)); if (output.getItem() instanceof BlockItem) { Block toPlace = Block.byItem(output.getItem()); - BlockState state2Place = toPlace.defaultBlockState(); //.getStateForPlacement(tile.getWorldObject(), pos, facing, 0, 0, 0, output.getMetadata(), FakePlayerFactory.getMinecraft((WorldServer) tile.getWorldObject()), Hand.MAIN_HAND); //TODO + BlockState state2Place = toPlace.defaultBlockState(); //.getStateForPlacement(tile.getWorldObject(), pos, facing, 0, 0, 0, stack.getMetadata(), FakePlayerFactory.getMinecraft((WorldServer) tile.getWorldObject()), Hand.MAIN_HAND); //TODO tile.getWorldObject().setBlock(pos, state2Place, 2); } else { ItemEntity item = new ItemEntity(tile.getWorldObject(), pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, output.copy()); @@ -172,7 +176,7 @@ public class MethodHandler implements IMethodHandler { tile.getWorldObject().setBlockAndUpdate(pos, Blocks.AIR.defaultBlockState()); } - tile.extractEnergy(recipe.get().getEnergy()); + tile.extractEnergy(recipe.getEnergy()); break; } } @@ -189,9 +193,10 @@ public class MethodHandler implements IMethodHandler { for (ItemEntity item : items) { ItemStack stack = item.getItem(); if (item.isAlive() && StackUtil.isValid(stack) && !item.getPersistentData().getBoolean("aa_cnv")) { - Optional recipe = LaserRecipe.getRecipeForStack(stack); - if (recipe.isPresent()) { - int itemsPossible = Math.min(tile.getEnergy() / recipe.get().getEnergy(), stack.getCount()); + Optional> holder = LaserRecipe.getRecipeForStack(stack); + if (holder.isPresent()) { + LaserRecipe recipe = holder.get().value(); + int itemsPossible = Math.min(tile.getEnergy() / recipe.getEnergy(), stack.getCount()); if (itemsPossible > 0) { //recipe.transformHook(item.getItem(), null, item.blockPosition(), tile); //TODO empty method @@ -205,14 +210,14 @@ public class MethodHandler implements IMethodHandler { tile.getWorldObject().addFreshEntity(inputLeft); } - ItemStack outputCopy = recipe.get().getResultItem(tile.getWorldObject().registryAccess()).copy(); + ItemStack outputCopy = recipe.getResultItem(tile.getWorldObject().registryAccess()).copy(); outputCopy.setCount(itemsPossible); ItemEntity newItem = new ItemEntity(tile.getWorldObject(), item.getX(), item.getY(), item.getZ(), outputCopy); newItem.getPersistentData().putBoolean("aa_cnv", true); tile.getWorldObject().addFreshEntity(newItem); - tile.extractEnergy(recipe.get().getEnergy() * itemsPossible); + tile.extractEnergy(recipe.getEnergy() * itemsPossible); break; } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/misc/apiimpl/farmer/DefaultFarmerBehavior.java b/src/main/java/de/ellpeck/actuallyadditions/mod/misc/apiimpl/farmer/DefaultFarmerBehavior.java index 36dd620cd..c90b404d6 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/misc/apiimpl/farmer/DefaultFarmerBehavior.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/misc/apiimpl/farmer/DefaultFarmerBehavior.java @@ -37,8 +37,8 @@ import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.level.storage.loot.LootParams; import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import net.minecraft.world.phys.Vec3; -import net.minecraftforge.common.IPlantable; -import net.minecraftforge.common.util.FakePlayerFactory; +import net.neoforged.neoforge.common.IPlantable; +import net.neoforged.neoforge.common.util.FakePlayerFactory; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/misc/apiimpl/farmer/NetherWartFarmerBehavior.java b/src/main/java/de/ellpeck/actuallyadditions/mod/misc/apiimpl/farmer/NetherWartFarmerBehavior.java index c4ea452cd..195e14b35 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/misc/apiimpl/farmer/NetherWartFarmerBehavior.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/misc/apiimpl/farmer/NetherWartFarmerBehavior.java @@ -27,7 +27,7 @@ import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.level.storage.loot.LootParams; import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import net.minecraft.world.phys.Vec3; -import net.minecraftforge.common.IPlantable; +import net.neoforged.neoforge.common.IPlantable; import java.util.List; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/misc/special/SpecialRenderInit.java b/src/main/java/de/ellpeck/actuallyadditions/mod/misc/special/SpecialRenderInit.java index 8c8e475bf..643188f6a 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/misc/special/SpecialRenderInit.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/misc/special/SpecialRenderInit.java @@ -11,14 +11,14 @@ package de.ellpeck.actuallyadditions.mod.misc.special; import de.ellpeck.actuallyadditions.mod.util.StackUtil; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.Block; -import net.minecraftforge.client.event.RenderPlayerEvent; -import net.minecraftforge.eventbus.api.EventPriority; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.registries.ForgeRegistries; +import net.neoforged.bus.api.EventPriority; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.neoforge.client.event.RenderPlayerEvent; import java.util.HashMap; import java.util.Locale; @@ -72,13 +72,13 @@ public class SpecialRenderInit { } private static ItemStack findItem(ResourceLocation resLoc) { - if (ForgeRegistries.ITEMS.containsKey(resLoc)) { - Item item = ForgeRegistries.ITEMS.getValue(resLoc); + if (BuiltInRegistries.ITEM.containsKey(resLoc)) { + Item item = BuiltInRegistries.ITEM.get(resLoc); if (item != null) { return new ItemStack(item); } - } else if (ForgeRegistries.BLOCKS.containsKey(resLoc)) { - Block block = ForgeRegistries.BLOCKS.getValue(resLoc); + } else if (BuiltInRegistries.BLOCK.containsKey(resLoc)) { + Block block = BuiltInRegistries.BLOCK.get(resLoc); if (block != null) { return new ItemStack(block); } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/network/IDataHandler.java b/src/main/java/de/ellpeck/actuallyadditions/mod/network/IDataHandler.java index e6bf22348..41a04ec9a 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/network/IDataHandler.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/network/IDataHandler.java @@ -11,10 +11,10 @@ package de.ellpeck.actuallyadditions.mod.network; import net.minecraft.nbt.CompoundTag; -import net.minecraftforge.network.NetworkEvent; +import net.neoforged.neoforge.network.handling.PlayPayloadContext; public interface IDataHandler { - void handleData(CompoundTag compound, NetworkEvent.Context context); + void handleData(CompoundTag compound, PlayPayloadContext context); } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketClientToServer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketClientToServer.java index 6684d2391..7b7eaf541 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketClientToServer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketClientToServer.java @@ -13,49 +13,53 @@ package de.ellpeck.actuallyadditions.mod.network; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.FriendlyByteBuf; -import net.minecraftforge.network.NetworkEvent; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.ResourceLocation; +import net.neoforged.neoforge.network.handling.PlayPayloadContext; +import org.apache.commons.lang3.tuple.Pair; -import java.util.function.Supplier; - -public class PacketClientToServer { - - private CompoundTag data; - private IDataHandler handler; - - public PacketClientToServer() { +public record PacketClientToServer(CompoundTag data, IDataHandler handler) implements CustomPacketPayload { + public static final ResourceLocation ID = new ResourceLocation(ActuallyAdditions.MODID, "client_to_server"); + public PacketClientToServer(Pair data) { + this(data.getLeft(), data.getRight()); } - public PacketClientToServer(CompoundTag data, IDataHandler handler) { - this.data = data; - this.handler = handler; + public PacketClientToServer(final FriendlyByteBuf buffer) { + this(fromBytes(buffer)); } - public static PacketClientToServer fromBytes(FriendlyByteBuf buffer) { + public static Pair fromBytes(FriendlyByteBuf buffer) { try { CompoundTag data = buffer.readNbt(); int handlerId = buffer.readInt(); if (handlerId >= 0 && handlerId < PacketHandler.DATA_HANDLERS.size()) { - return new PacketClientToServer(data, PacketHandler.DATA_HANDLERS.get(handlerId)); + return Pair.of(data, PacketHandler.DATA_HANDLERS.get(handlerId)); } } catch (Exception e) { ActuallyAdditions.LOGGER.error("Something went wrong trying to receive a server packet!", e); } - return new PacketClientToServer(); + return Pair.of(null, null); } - public static void toBytes(PacketClientToServer message, FriendlyByteBuf buffer) { - buffer.writeNbt(message.data); - buffer.writeInt(PacketHandler.DATA_HANDLERS.indexOf(message.handler)); + public void write(FriendlyByteBuf buf) { + buf.writeNbt(data); + buf.writeInt(PacketHandler.DATA_HANDLERS.indexOf(handler)); } - public static void handle(final PacketClientToServer message, final Supplier ctx) { - ctx.get().enqueueWork( () -> { - if (message.data != null && message.handler != null) { - message.handler.handleData(message.data, ctx.get()); - } - }); - ctx.get().setPacketHandled(true); + public static void handle(final PacketClientToServer message, final PlayPayloadContext context) { + context.workHandler().submitAsync( + () -> { + if (message.data != null && message.handler != null) { + message.handler.handleData(message.data, context); + } + } + ); + } + + @Override + public ResourceLocation id() { + return ID; } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandler.java b/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandler.java index 49ab45a74..bc2db3f23 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandler.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandler.java @@ -23,23 +23,21 @@ import net.minecraft.client.Minecraft; import net.minecraft.core.BlockPos; import net.minecraft.core.registries.Registries; import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.common.util.FakePlayer; -import net.minecraftforge.network.NetworkDirection; -import net.minecraftforge.network.NetworkEvent; -import net.minecraftforge.network.NetworkRegistry; -import net.minecraftforge.network.PacketDistributor; -import net.minecraftforge.network.simple.SimpleChannel; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; +import net.neoforged.neoforge.network.PacketDistributor; +import net.neoforged.neoforge.network.event.RegisterPayloadHandlerEvent; +import net.neoforged.neoforge.network.handling.PlayPayloadContext; +import net.neoforged.neoforge.network.registration.IPayloadRegistrar; import java.util.ArrayList; import java.util.List; @@ -50,14 +48,14 @@ public final class PacketHandler { public static final IDataHandler LASER_HANDLER = new IDataHandler() { @Override @OnlyIn(Dist.CLIENT) - public void handleData(CompoundTag compound, NetworkEvent.Context context) { + public void handleData(CompoundTag compound, PlayPayloadContext context) { AssetUtil.spawnLaserWithTimeClient(compound.getDouble("StartX"), compound.getDouble("StartY"), compound.getDouble("StartZ"), compound.getDouble("EndX"), compound.getDouble("EndY"), compound.getDouble("EndZ"), compound.getInt("Color"), compound.getInt("MaxAge"), compound.getDouble("RotationTime"), compound.getFloat("Size"), compound.getFloat("Alpha")); } }; public static final IDataHandler TILE_ENTITY_HANDLER = new IDataHandler() { @Override @OnlyIn(Dist.CLIENT) - public void handleData(CompoundTag compound, NetworkEvent.Context context) { + public void handleData(CompoundTag compound, PlayPayloadContext context) { Level world = Minecraft.getInstance().level; if (world != null) { BlockEntity tile = world.getBlockEntity(new BlockPos(compound.getInt("X"), compound.getInt("Y"), compound.getInt("Z"))); @@ -70,7 +68,7 @@ public final class PacketHandler { public static final IDataHandler LASER_PARTICLE_HANDLER = new IDataHandler() { @Override @OnlyIn(Dist.CLIENT) - public void handleData(CompoundTag compound, NetworkEvent.Context context) { + public void handleData(CompoundTag compound, PlayPayloadContext context) { Minecraft mc = Minecraft.getInstance(); ItemStack stack = ItemStack.of(compound); @@ -90,48 +88,60 @@ public final class PacketHandler { } }; public static final IDataHandler GUI_BUTTON_TO_TILE_HANDLER = (compound, context) -> { - Level world = context.getSender().getServer().getLevel(ResourceKey.create(Registries.DIMENSION, new ResourceLocation(compound.getString("WorldID")))); - BlockEntity tile = world.getBlockEntity(new BlockPos(compound.getInt("X"), compound.getInt("Y"), compound.getInt("Z"))); + if (context.player().isPresent()) { + Player player = context.player().get(); + Level level = player.getServer().getLevel(ResourceKey.create(Registries.DIMENSION, new ResourceLocation(compound.getString("WorldID")))); + BlockEntity tile = level.getBlockEntity(new BlockPos(compound.getInt("X"), compound.getInt("Y"), compound.getInt("Z"))); - if (tile instanceof IButtonReactor reactor) { - Entity entity = world.getEntity(compound.getInt("PlayerID")); - if (entity instanceof Player) { - reactor.onButtonPressed(compound.getInt("ButtonID"), (Player) entity); + if (tile instanceof IButtonReactor reactor) { + Entity entity = level.getEntity(compound.getInt("PlayerID")); + if (entity instanceof Player) { + reactor.onButtonPressed(compound.getInt("ButtonID"), (Player) entity); + } } } }; public static final IDataHandler GUI_BUTTON_TO_CONTAINER_HANDLER = (compound, context) -> { - Level world = context.getSender().getServer().getLevel(ResourceKey.create(Registries.DIMENSION, new ResourceLocation(compound.getString("WorldID")))); - Entity entity = world.getEntity(compound.getInt("PlayerID")); - if (entity instanceof Player) { - AbstractContainerMenu container = ((Player) entity).containerMenu; - if (container instanceof IButtonReactor) { - ((IButtonReactor) container).onButtonPressed(compound.getInt("ButtonID"), (Player) entity); + if (context.player().isPresent()) { + Player player = context.player().get(); + Level level = player.getServer().getLevel(ResourceKey.create(Registries.DIMENSION, new ResourceLocation(compound.getString("WorldID")))); + Entity entity = level.getEntity(compound.getInt("PlayerID")); + if (entity instanceof Player) { + AbstractContainerMenu container = ((Player) entity).containerMenu; + if (container instanceof IButtonReactor) { + ((IButtonReactor) container).onButtonPressed(compound.getInt("ButtonID"), (Player) entity); + } } } }; public static final IDataHandler GUI_NUMBER_TO_TILE_HANDLER = (compound, context) -> { - Level world = context.getSender().getServer().getLevel(ResourceKey.create(Registries.DIMENSION, new ResourceLocation(compound.getString("WorldID")))); - BlockEntity tile = world.getBlockEntity(new BlockPos(compound.getInt("X"), compound.getInt("Y"), compound.getInt("Z"))); + if (context.player().isPresent()) { + Player player = context.player().get(); + Level level = player.getServer().getLevel(ResourceKey.create(Registries.DIMENSION, new ResourceLocation(compound.getString("WorldID")))); + BlockEntity tile = level.getBlockEntity(new BlockPos(compound.getInt("X"), compound.getInt("Y"), compound.getInt("Z"))); - if (tile instanceof INumberReactor reactor) { - reactor.onNumberReceived(compound.getDouble("Number"), compound.getInt("NumberID"), (Player) world.getEntity(compound.getInt("PlayerID"))); + if (tile instanceof INumberReactor reactor) { + reactor.onNumberReceived(compound.getDouble("Number"), compound.getInt("NumberID"), (Player) level.getEntity(compound.getInt("PlayerID"))); + } } }; public static final IDataHandler GUI_STRING_TO_TILE_HANDLER = (compound, context) -> { - Level world = context.getSender().getServer().getLevel(ResourceKey.create(Registries.DIMENSION, new ResourceLocation(compound.getString("WorldID")))); - BlockEntity tile = world.getBlockEntity(new BlockPos(compound.getInt("X"), compound.getInt("Y"), compound.getInt("Z"))); + if (context.player().isPresent()) { + Player player = context.player().get(); + Level level = player.getServer().getLevel(ResourceKey.create(Registries.DIMENSION, new ResourceLocation(compound.getString("WorldID")))); + BlockEntity tile = level.getBlockEntity(new BlockPos(compound.getInt("X"), compound.getInt("Y"), compound.getInt("Z"))); - if (tile instanceof IStringReactor reactor) { - reactor.onTextReceived(compound.getString("Text"), compound.getInt("TextID"), (Player) world.getEntity(compound.getInt("PlayerID"))); + if (tile instanceof IStringReactor reactor) { + reactor.onTextReceived(compound.getString("Text"), compound.getInt("TextID"), (Player) level.getEntity(compound.getInt("PlayerID"))); + } } }; public static final IDataHandler SYNC_PLAYER_DATA = new IDataHandler() { @Override @OnlyIn(Dist.CLIENT) - public void handleData(CompoundTag compound, NetworkEvent.Context context) { + public void handleData(CompoundTag compound, PlayPayloadContext context) { CompoundTag dataTag = compound.getCompound("Data"); - Player player = context.getSender(); //ActuallyAdditions.PROXY.getCurrentPlayer(); + Player player = context.player().get(); //ActuallyAdditions.PROXY.getCurrentPlayer(); if (player != null) { PlayerData.getDataFromPlayer(player).readFromNBT(dataTag, false); @@ -145,52 +155,42 @@ public final class PacketHandler { } }; public static final IDataHandler PLAYER_DATA_TO_SERVER = (compound, context) -> { - Level world = context.getSender().getServer().getLevel(ResourceKey.create(Registries.DIMENSION, new ResourceLocation(compound.getString("World")))); - Player player = world.getServer().getPlayerList().getPlayer(compound.getUUID("UUID")); - if (player != null) { - PlayerData.PlayerSave data = PlayerData.getDataFromPlayer(player); + if (context.player().isPresent()) { + Level level = context.player().get().getServer().getLevel(ResourceKey.create(Registries.DIMENSION, new ResourceLocation(compound.getString("World")))); + Player player = level.getServer().getPlayerList().getPlayer(compound.getUUID("UUID")); + if (player != null) { + PlayerData.PlayerSave data = PlayerData.getDataFromPlayer(player); - int type = compound.getInt("Type"); - if (type == 0) { - data.loadBookmarks(compound.getList("Bookmarks", 8)); - } else if (type == 1) { - data.didBookTutorial = compound.getBoolean("DidBookTutorial"); - } else if (type == 2) { - data.loadTrials(compound.getList("Trials", 8)); + int type = compound.getInt("Type"); + if (type == 0) { + data.loadBookmarks(compound.getList("Bookmarks", 8)); + } else if (type == 1) { + data.didBookTutorial = compound.getBoolean("DidBookTutorial"); + } else if (type == 2) { + data.loadTrials(compound.getList("Trials", 8)); - if (compound.getBoolean("Achievement")) { - //TheAchievements.COMPLETE_TRIALS.get(player); + if (compound.getBoolean("Achievement")) { + //TheAchievements.COMPLETE_TRIALS.get(player); + } } - } - WorldData.get(world).setDirty(); + WorldData.get(level).setDirty(); - if (compound.getBoolean("Log")) { - ActuallyAdditions.LOGGER.info("Receiving changed Player Data for player " + player.getName() + "."); + if (compound.getBoolean("Log")) { + ActuallyAdditions.LOGGER.info("Receiving changed Player Data for player " + player.getName() + "."); + } + } else { + ActuallyAdditions.LOGGER.error("Tried to receive Player Data for UUID " + compound.getUUID("UUID") + ", but he doesn't seem to be present!"); } - } else { - ActuallyAdditions.LOGGER.error("Tried to receive Player Data for UUID " + compound.getUUID("UUID") + ", but he doesn't seem to be present!"); } }; - private static final String PROTOCOL_VERSION = Integer.toString(4); - public static final SimpleChannel THE_NETWORK = NetworkRegistry.newSimpleChannel( - new ResourceLocation(ActuallyAdditions.MODID, "main"), - () -> PROTOCOL_VERSION, - PROTOCOL_VERSION::equals, - PROTOCOL_VERSION::equals - ); - - public static void init() { - THE_NETWORK.messageBuilder(PacketServerToClient.class, 0, NetworkDirection.PLAY_TO_CLIENT) - .decoder(PacketServerToClient::fromBytes) - .encoder(PacketServerToClient::toBytes) - .consumerNetworkThread(PacketServerToClient::handle).add(); - - THE_NETWORK.messageBuilder(PacketClientToServer.class, 1, NetworkDirection.PLAY_TO_SERVER) - .decoder(PacketClientToServer::fromBytes) - .encoder(PacketClientToServer::toBytes) - .consumerNetworkThread(PacketClientToServer::handle).add(); + public static void register(final RegisterPayloadHandlerEvent event) { + final IPayloadRegistrar registrar = event.registrar(ActuallyAdditions.MODID); + registrar.play(PacketServerToClient.ID, PacketServerToClient::new, handler -> handler + .client(PacketServerToClient::handle)); + registrar.play(PacketClientToServer.ID, PacketClientToServer::new, handler -> handler + .server(PacketClientToServer::handle)); DATA_HANDLERS.add(LASER_HANDLER); DATA_HANDLERS.add(TILE_ENTITY_HANDLER); @@ -203,17 +203,7 @@ public final class PacketHandler { DATA_HANDLERS.add(PLAYER_DATA_TO_SERVER); } - public static void sendTo(Object msg, ServerPlayer player) { - if (!(player instanceof FakePlayer)) { - THE_NETWORK.sendTo(msg, player.connection.connection, NetworkDirection.PLAY_TO_CLIENT); - } - } - - public static void sendToServer(Object msg) { - THE_NETWORK.sendToServer(msg); - } - - public static void send(Object msg, PacketDistributor.PacketTarget target) { - THE_NETWORK.send(target, msg); + public static void send(CustomPacketPayload msg, PacketDistributor.PacketTarget target) { + target.send(msg); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandlerHelper.java b/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandlerHelper.java index 985c86692..62cabea6a 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandlerHelper.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandlerHelper.java @@ -20,9 +20,9 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.network.PacketDistributor; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; +import net.neoforged.neoforge.network.PacketDistributor; public final class PacketHandlerHelper { @@ -36,7 +36,7 @@ public final class PacketHandlerHelper { compound.putString("WorldID", tile.getLevel().dimension().location().toString()); compound.putInt("PlayerID", Minecraft.getInstance().player.getId()); compound.putInt("ButtonID", buttonId); - PacketHandler.THE_NETWORK.sendToServer(new PacketClientToServer(compound, PacketHandler.GUI_BUTTON_TO_TILE_HANDLER)); + PacketDistributor.SERVER.noArg().send(new PacketClientToServer(compound, PacketHandler.GUI_BUTTON_TO_TILE_HANDLER)); } public static void syncPlayerData(Player player, boolean log) { @@ -48,7 +48,7 @@ public final class PacketHandlerHelper { compound.put("Data", data); if (player instanceof ServerPlayer) { - PacketHandler.THE_NETWORK.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new PacketServerToClient(compound, PacketHandler.SYNC_PLAYER_DATA)); + ((ServerPlayer) player).connection.send(new PacketServerToClient(compound, PacketHandler.SYNC_PLAYER_DATA)); } } @@ -84,7 +84,7 @@ public final class PacketHandlerHelper { } } - PacketHandler.THE_NETWORK.sendToServer(new PacketClientToServer(compound, PacketHandler.PLAYER_DATA_TO_SERVER)); + PacketDistributor.SERVER.noArg().send(new PacketClientToServer(compound, PacketHandler.PLAYER_DATA_TO_SERVER)); } } @@ -98,6 +98,6 @@ public final class PacketHandlerHelper { compound.putInt("PlayerID", Minecraft.getInstance().player.getId()); compound.putInt("NumberID", id); compound.putDouble("Number", number); - PacketHandler.THE_NETWORK.sendToServer(new PacketClientToServer(compound, PacketHandler.GUI_NUMBER_TO_TILE_HANDLER)); + PacketDistributor.SERVER.noArg().send(new PacketClientToServer(compound, PacketHandler.GUI_NUMBER_TO_TILE_HANDLER)); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketServerToClient.java b/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketServerToClient.java index 6fb5f0a86..eaf41f360 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketServerToClient.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketServerToClient.java @@ -13,52 +13,54 @@ package de.ellpeck.actuallyadditions.mod.network; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.FriendlyByteBuf; -import net.minecraftforge.network.NetworkEvent; - -import java.util.function.Supplier; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.ResourceLocation; +import net.neoforged.neoforge.network.handling.PlayPayloadContext; +import org.apache.commons.lang3.tuple.Pair; -public class PacketServerToClient { - - private CompoundTag data; - private IDataHandler handler; - - public PacketServerToClient() { +public record PacketServerToClient(CompoundTag data, IDataHandler handler) implements CustomPacketPayload { + public static final ResourceLocation ID = new ResourceLocation(ActuallyAdditions.MODID, "server_to_client"); + public PacketServerToClient(Pair data) { + this(data.getLeft(), data.getRight()); } - public PacketServerToClient(CompoundTag data, IDataHandler handler) { - this.data = data; - this.handler = handler; + public PacketServerToClient(final FriendlyByteBuf buffer) { + this(fromBytes(buffer)); } - public static PacketServerToClient fromBytes(final FriendlyByteBuf buffer) { + public static Pair fromBytes(FriendlyByteBuf buffer) { try { CompoundTag data = buffer.readNbt(); int handlerId = buffer.readInt(); if (handlerId >= 0 && handlerId < PacketHandler.DATA_HANDLERS.size()) { - return new PacketServerToClient(data, PacketHandler.DATA_HANDLERS.get(handlerId)); + return Pair.of(data, PacketHandler.DATA_HANDLERS.get(handlerId)); } } catch (Exception e) { ActuallyAdditions.LOGGER.error("Something went wrong trying to receive a client packet!", e); } - return new PacketServerToClient(); + return Pair.of(null, null); } - public static void toBytes(final PacketServerToClient message, FriendlyByteBuf buffer) { - buffer.writeNbt(message.data); - buffer.writeInt(PacketHandler.DATA_HANDLERS.indexOf(message.handler)); + public void write(FriendlyByteBuf buf) { + buf.writeNbt(data); + buf.writeInt(PacketHandler.DATA_HANDLERS.indexOf(handler)); } - public static void handle(final PacketServerToClient message, final Supplier ctx) { - ctx.get().enqueueWork( + @Override + public ResourceLocation id() { + return ID; + } + + public static void handle(final PacketServerToClient message, final PlayPayloadContext context) { + context.workHandler().submitAsync( () -> { if (message.data != null && message.handler != null) { - message.handler.handleData(message.data, ctx.get()); + message.handler.handleData(message.data, context); } - } - ); - ctx.get().setPacketHandled(true); + } + ); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/particle/ActuallyParticles.java b/src/main/java/de/ellpeck/actuallyadditions/mod/particle/ActuallyParticles.java index e0098657f..f15607fa3 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/particle/ActuallyParticles.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/particle/ActuallyParticles.java @@ -2,17 +2,18 @@ package de.ellpeck.actuallyadditions.mod.particle; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import net.minecraft.core.particles.ParticleType; -import net.minecraftforge.eventbus.api.IEventBus; -import net.minecraftforge.registries.DeferredRegister; -import net.minecraftforge.registries.ForgeRegistries; -import net.minecraftforge.registries.RegistryObject; +import net.minecraft.core.registries.BuiltInRegistries; +import net.neoforged.bus.api.IEventBus; +import net.neoforged.neoforge.registries.DeferredRegister; + +import java.util.function.Supplier; public class ActuallyParticles { - private static final DeferredRegister> PARTICLE_TYPES = DeferredRegister.create(ForgeRegistries.PARTICLE_TYPES, ActuallyAdditions.MODID); + private static final DeferredRegister> PARTICLE_TYPES = DeferredRegister.create(BuiltInRegistries.PARTICLE_TYPE, ActuallyAdditions.MODID); - public static final RegistryObject> LASER_ITEM = PARTICLE_TYPES.register("laser_item", LaserItemParticleType::new); - public static final RegistryObject> BEAM = PARTICLE_TYPES.register("beam", BeamParticleType::new); + public static final Supplier> LASER_ITEM = PARTICLE_TYPES.register("laser_item", LaserItemParticleType::new); + public static final Supplier> BEAM = PARTICLE_TYPES.register("beam", BeamParticleType::new); public static void init(IEventBus evt) { PARTICLE_TYPES.register(evt); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/particle/LaserItemParticleData.java b/src/main/java/de/ellpeck/actuallyadditions/mod/particle/LaserItemParticleData.java index f5b00a846..1dc23cac6 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/particle/LaserItemParticleData.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/particle/LaserItemParticleData.java @@ -6,11 +6,11 @@ import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; import net.minecraft.core.particles.ParticleOptions; import net.minecraft.core.particles.ParticleType; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; -import net.minecraftforge.registries.ForgeRegistries; import java.util.Locale; @@ -33,7 +33,7 @@ public class LaserItemParticleData extends ParticleType i reader.expect(' '); String itemString = reader.readString(); ResourceLocation itemLocation = ResourceLocation.tryParse(itemString); - Item item = itemLocation == null ? null : ForgeRegistries.ITEMS.getValue(itemLocation); + Item item = itemLocation == null ? null : BuiltInRegistries.ITEM.get(itemLocation); ItemStack stack = item == null ? ItemStack.EMPTY : new ItemStack(item); reader.expect(' '); double outputX = reader.readDouble(); @@ -75,7 +75,7 @@ public class LaserItemParticleData extends ParticleType i @Override public void writeToNetwork(FriendlyByteBuf buffer) { - buffer.writeItemStack(this.stack, true); + buffer.writeItem(this.stack); buffer.writeDouble(this.outputX); buffer.writeDouble(this.outputY); buffer.writeDouble(this.outputZ); @@ -83,8 +83,8 @@ public class LaserItemParticleData extends ParticleType i @Override public String writeToString() { - return String.format(Locale.ROOT, "%s %s %.2f %.2f %.2f", ForgeRegistries.PARTICLE_TYPES.getKey(this.getType()), - ForgeRegistries.ITEMS.getKey(this.stack.getItem()), + return String.format(Locale.ROOT, "%s %s %.2f %.2f %.2f", BuiltInRegistries.PARTICLE_TYPE.getKey(this.getType()), + BuiltInRegistries.ITEM.getKey(this.stack.getItem()), this.outputX, this.outputY, this.outputZ); } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/recipe/CrusherRecipeRegistry.java b/src/main/java/de/ellpeck/actuallyadditions/mod/recipe/CrusherRecipeRegistry.java index 29555417d..b1f729393 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/recipe/CrusherRecipeRegistry.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/recipe/CrusherRecipeRegistry.java @@ -13,6 +13,7 @@ package de.ellpeck.actuallyadditions.mod.recipe; import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; import de.ellpeck.actuallyadditions.mod.crafting.CrushingRecipe; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.RecipeHolder; public final class CrusherRecipeRegistry { // @@ -29,13 +30,13 @@ public final class CrusherRecipeRegistry { // if (ore.substring(0, theCase.theCase.length()).equals(theCase.theCase)) { // String outputOre = theCase.resultPreString + ore.substring(theCase.theCase.length()); // List outputs = OreDictionary.getOres(outputOre, false); - // ItemStack output = outputs.isEmpty() ? ItemStack.EMPTY : outputs.get(0).copy(); - // output.setCount(theCase.resultAmount); - // if (output.isEmpty()) { + // ItemStack stack = outputs.isEmpty() ? ItemStack.EMPTY : outputs.get(0).copy(); + // stack.setCount(theCase.resultAmount); + // if (stack.isEmpty()) { // if (!oresNoResult.contains(ore)) { // oresNoResult.add(ore); // } - // } else ActuallyAdditionsAPI.addCrusherRecipe(new OreIngredient(ore), output, StackUtil.getEmpty(), 0); + // } else ActuallyAdditionsAPI.addCrusherRecipe(new OreIngredient(ore), stack, StackUtil.getEmpty(), 0); // } // } // } @@ -71,9 +72,9 @@ public final class CrusherRecipeRegistry { // ActuallyAdditions.LOGGER.debug(String.format("Removed %s crusher recipes that had dupliate inputs, %s remain.", removed.size(), usable.size())); // } // - // public static boolean hasBlacklistedOutput(ItemStack output, String[] config) { - // if (StackUtil.isValid(output)) { - // Item item = output.getItem(); + // public static boolean hasBlacklistedOutput(ItemStack stack, String[] config) { + // if (StackUtil.isValid(stack)) { + // Item item = stack.getItem(); // if (item != null) { // String reg = item.getRegistryName().toString(); // @@ -91,7 +92,7 @@ public final class CrusherRecipeRegistry { // } // } // - // if (reg.equals(confReg) && output.getItemDamage() == meta) { return true; } + // if (reg.equals(confReg) && stack.getItemDamage() == meta) { return true; } // } // // return false; @@ -108,8 +109,8 @@ public final class CrusherRecipeRegistry { // } // public static CrushingRecipe getRecipeFromInput(ItemStack input) { - for (CrushingRecipe recipe : ActuallyAdditionsAPI.CRUSHER_RECIPES) - if (recipe.matches(input)) return recipe; + for (RecipeHolder holder : ActuallyAdditionsAPI.CRUSHER_RECIPES) + if (holder.value().matches(input)) return holder.value(); return null; } // diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/sack/SackData.java b/src/main/java/de/ellpeck/actuallyadditions/mod/sack/SackData.java index 7638a8d27..a84abade5 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/sack/SackData.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/sack/SackData.java @@ -2,9 +2,8 @@ package de.ellpeck.actuallyadditions.mod.sack; import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA; import net.minecraft.nbt.CompoundTag; -import net.minecraftforge.common.util.INBTSerializable; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.items.IItemHandler; +import net.neoforged.neoforge.common.util.INBTSerializable; +import net.neoforged.neoforge.items.IItemHandler; import java.util.Optional; import java.util.UUID; @@ -15,11 +14,11 @@ public class SackData { private final UUID uuid; private final ItemStackHandlerAA inventory; - private final LazyOptional optional; + private final Optional optional; public final Metadata meta = new Metadata(); - public LazyOptional getOptional() { + public Optional getOptional() { return optional; } @@ -51,7 +50,7 @@ public class SackData { SackManager.get().setDirty(); } }; - optional = LazyOptional.of(() -> inventory); + optional = Optional.ofNullable(inventory); } public SackData(UUID uuid, CompoundTag incoming) { @@ -68,7 +67,7 @@ public class SackData { inventory.deserializeNBT(incoming.getCompound("Inventory")); - optional = LazyOptional.of(() -> inventory); + optional = Optional.ofNullable(inventory); if (incoming.contains("Metadata")) meta.deserializeNBT(incoming.getCompound("Metadata")); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/sack/SackManager.java b/src/main/java/de/ellpeck/actuallyadditions/mod/sack/SackManager.java index 453568033..075c1fd81 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/sack/SackManager.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/sack/SackManager.java @@ -6,10 +6,9 @@ import net.minecraft.nbt.ListTag; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.saveddata.SavedData; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.fml.util.thread.SidedThreadGroups; -import net.minecraftforge.items.IItemHandler; -import net.minecraftforge.server.ServerLifecycleHooks; +import net.neoforged.fml.util.thread.SidedThreadGroups; +import net.neoforged.neoforge.items.IItemHandler; +import net.neoforged.neoforge.server.ServerLifecycleHooks; import javax.annotation.Nonnull; import java.util.HashMap; @@ -29,7 +28,7 @@ public class SackManager extends SavedData { public static SackManager get() { if (Thread.currentThread().getThreadGroup() == SidedThreadGroups.SERVER) - return ServerLifecycleHooks.getCurrentServer().getLevel(Level.OVERWORLD).getDataStorage().computeIfAbsent(SackManager::load, SackManager::new, NAME); + return ServerLifecycleHooks.getCurrentServer().getLevel(Level.OVERWORLD).getDataStorage().computeIfAbsent(new Factory<>(SackManager::new, SackManager::load), NAME); else return blankClient; } @@ -48,27 +47,27 @@ public class SackManager extends SavedData { } public void removeSack(UUID uuid) { getSack(uuid).ifPresent(backpack -> { - backpack.getOptional().invalidate(); +// backpack.getOptional().invalidate(); data.remove(uuid); setDirty(); }); } - public LazyOptional getCapability(UUID uuid) { + public Optional getCapability(UUID uuid) { if (data.containsKey(uuid)) return data.get(uuid).getOptional(); - return LazyOptional.empty(); + return Optional.empty(); } - public LazyOptional getCapability(ItemStack stack) { + public Optional getCapability(ItemStack stack) { if (stack.getOrCreateTag().contains("UUID")) { UUID uuid = stack.getTag().getUUID("UUID"); if (data.containsKey(uuid)) return data.get(uuid).getOptional(); } - return LazyOptional.empty(); + return Optional.empty(); } public static SackManager load(CompoundTag nbt) { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/CustomEnergyStorage.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/CustomEnergyStorage.java index 89d17e08c..f8c264c9d 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/CustomEnergyStorage.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/CustomEnergyStorage.java @@ -11,7 +11,7 @@ package de.ellpeck.actuallyadditions.mod.tile; import net.minecraft.nbt.CompoundTag; -import net.minecraftforge.energy.EnergyStorage; +import net.neoforged.neoforge.energy.EnergyStorage; public class CustomEnergyStorage extends EnergyStorage { boolean dirty = false; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/FilterSettings.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/FilterSettings.java index 68580d557..9651cf699 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/FilterSettings.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/FilterSettings.java @@ -14,10 +14,10 @@ import de.ellpeck.actuallyadditions.mod.inventory.ContainerFilter; import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotFilter; import de.ellpeck.actuallyadditions.mod.items.DrillItem; import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.nbt.CompoundTag; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; -import net.minecraftforge.registries.ForgeRegistries; public class FilterSettings { public final ItemStackHandlerAA filterInventory; @@ -69,7 +69,7 @@ public class FilterSettings { private static boolean areEqualEnough(ItemStack first, ItemStack second, boolean nbt, boolean mod) { Item firstItem = first.getItem(); Item secondItem = second.getItem(); - if (mod && ForgeRegistries.ITEMS.getKey(firstItem).getNamespace().equals(ForgeRegistries.ITEMS.getKey(secondItem).getNamespace())) { + if (mod && BuiltInRegistries.ITEM.getKey(firstItem).getNamespace().equals(BuiltInRegistries.ITEM.getKey(secondItem).getNamespace())) { return true; } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/IEnergyDisplay.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/IEnergyDisplay.java index 810ded57b..8637e7498 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/IEnergyDisplay.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/IEnergyDisplay.java @@ -10,8 +10,8 @@ package de.ellpeck.actuallyadditions.mod.tile; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; public interface IEnergyDisplay { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityAtomicReconstructor.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityAtomicReconstructor.java index 328e8ba1f..2a4cc1f1f 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityAtomicReconstructor.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityAtomicReconstructor.java @@ -29,16 +29,12 @@ import net.minecraft.world.item.Item; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.state.properties.BlockStateProperties; -import net.minecraft.world.phys.AABB; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.energy.IEnergyStorage; +import net.neoforged.neoforge.energy.IEnergyStorage; public class TileEntityAtomicReconstructor extends TileEntityInventoryBase implements IEnergyDisplay, IAtomicReconstructor { public static final int ENERGY_USE = 1000; public final CustomEnergyStorage storage; - public final LazyOptional lazyEnergy; public int counter; private int currentTime; private int oldEnergy; @@ -51,7 +47,6 @@ public class TileEntityAtomicReconstructor extends TileEntityInventoryBase imple int power = CommonConfig.Machines.RECONSTRUCTOR_POWER.get(); int recieve = Mth.ceil(power * 0.016666F); this.storage = new CustomEnergyStorage(power, recieve, 0); - this.lazyEnergy = LazyOptional.of(() -> this.storage); } public static void shootLaser(IAtomicReconstructor tile, Level world, double startX, double startY, double startZ, double endX, double endY, double endZ, Lens currentLens) { @@ -59,14 +54,6 @@ public class TileEntityAtomicReconstructor extends TileEntityInventoryBase imple AssetUtil.spawnLaserWithTimeServer(world, startX, startY, startZ, endX, endY, endZ, currentLens.getColor(), 25, 0, 0.2F, 0.8F); } - @Override - public AABB getRenderBoundingBox() { - if (getProgress() > 0.0f) - return new AABB(getPosition(), getPosition().offset(1,1,1).relative(getBlockState().getValue(BlockStateProperties.FACING), 11)); - else - return super.getRenderBoundingBox(); - } - @Override public int getTTL() { return this.ttl; @@ -230,7 +217,7 @@ public class TileEntityAtomicReconstructor extends TileEntityInventoryBase imple } @Override - public LazyOptional getEnergyStorage(Direction facing) { - return this.lazyEnergy; + public IEnergyStorage getEnergyStorage(Direction facing) { + return this.storage; } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBase.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBase.java index 0f0f49173..7e85bb333 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBase.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBase.java @@ -21,14 +21,10 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; 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.capability.IFluidHandler; -import net.minecraftforge.items.IItemHandler; +import net.neoforged.neoforge.energy.IEnergyStorage; +import net.neoforged.neoforge.fluids.capability.IFluidHandler; +import net.neoforged.neoforge.items.IItemHandler; -import javax.annotation.Nonnull; import javax.annotation.Nullable; public abstract class TileEntityBase extends BlockEntity { @@ -193,7 +189,7 @@ public abstract class TileEntityBase extends BlockEntity { for (Direction side : sides) { BlockEntity tile = this.tilesAround[side.ordinal()]; if (tile != null && provider.canShareTo(tile)) { - WorldUtil.doEnergyInteraction(this, tile, side, amount); + WorldUtil.doEnergyInteraction(this.level, this.getBlockPos(), tile.getBlockPos(), side, amount); } } } @@ -215,7 +211,7 @@ public abstract class TileEntityBase extends BlockEntity { for (Direction side : sides) { BlockEntity tile = this.tilesAround[side.ordinal()]; if (tile != null) { - WorldUtil.doFluidInteraction(this, tile, side, amount); + WorldUtil.doFluidInteraction(this.level, this.getBlockPos(), tile.getBlockPos(), side, amount); } } } @@ -262,29 +258,16 @@ public abstract class TileEntityBase extends BlockEntity { } } - @Nonnull - @Override - public LazyOptional getCapability(@Nonnull Capability capability, @Nullable Direction side) { - if (capability == ForgeCapabilities.ITEM_HANDLER) { - return this.getItemHandler(side).cast(); - } else if (capability == ForgeCapabilities.FLUID_HANDLER) { - return this.getFluidHandler(side).cast(); - } else if (capability == ForgeCapabilities.ENERGY) { - return this.getEnergyStorage(side).cast(); - } - return LazyOptional.empty(); + public IFluidHandler getFluidHandler(Direction facing) { + return null; } - public LazyOptional getFluidHandler(Direction facing) { - return LazyOptional.empty(); + public IEnergyStorage getEnergyStorage(Direction facing) { + return null; } - public LazyOptional getEnergyStorage(Direction facing) { - return LazyOptional.empty(); - } - - public LazyOptional getItemHandler(Direction facing) { - return LazyOptional.empty(); + public IItemHandler getItemHandler(Direction facing) { + return null; } public boolean isRedstoneToggle() { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBatteryBox.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBatteryBox.java index b81879c69..9ca8de363 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBatteryBox.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBatteryBox.java @@ -20,12 +20,12 @@ import net.minecraft.world.item.ItemStack; 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.ForgeCapabilities; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.energy.IEnergyStorage; +import net.neoforged.neoforge.capabilities.Capabilities; +import net.neoforged.neoforge.energy.IEnergyStorage; import java.util.ArrayList; import java.util.List; +import java.util.Optional; public class TileEntityBatteryBox extends TileEntityInventoryBase implements ISharingEnergyProvider { @@ -37,12 +37,12 @@ public class TileEntityBatteryBox extends TileEntityInventoryBase implements ISh } @Override - public LazyOptional getEnergyStorage(Direction facing) { + public IEnergyStorage getEnergyStorage(Direction facing) { ItemStack stack = this.inv.getStackInSlot(0); if (stack.getItem() instanceof ItemBattery) { - return stack.getCapability(ForgeCapabilities.ENERGY, null); + return stack.getCapability(Capabilities.EnergyStorage.ITEM, null); } - return LazyOptional.empty(); + return null; } public static void clientTick(Level level, BlockPos pos, BlockState state, T t) { @@ -55,7 +55,7 @@ public class TileEntityBatteryBox extends TileEntityInventoryBase implements ISh if (t instanceof TileEntityBatteryBox tile) { tile.serverTick(); - LazyOptional cap = tile.getEnergyStorage(null); + Optional cap = Optional.ofNullable(tile.getEnergyStorage(null)); int currStorage = cap.map(storage -> { ItemStack stack = tile.inv.getStackInSlot(0); if (!stack.isEmpty() && ItemUtil.isEnabled(stack)) { @@ -75,7 +75,7 @@ public class TileEntityBatteryBox extends TileEntityInventoryBase implements ISh for (TileEntityBatteryBox te : tiles) { ItemStack battery = te.inv.getStackInSlot(0); if (!battery.isEmpty() && !ItemUtil.isEnabled(battery)) { - int received = te.getCapability(ForgeCapabilities.ENERGY, null).map(e -> e.receiveEnergy(maxPer, false)).orElse(0); + int received = Optional.ofNullable(level.getCapability(Capabilities.EnergyStorage.BLOCK, te.getBlockPos(), null)).map(e -> e.receiveEnergy(maxPer, false)).orElse(0); storage.extractEnergy(received, false); if (storage.getEnergyStored() <= 0) { @@ -109,7 +109,7 @@ public class TileEntityBatteryBox extends TileEntityInventoryBase implements ISh @Override public int getComparatorStrength() { - return this.getEnergyStorage(null) + return Optional.ofNullable(this.getEnergyStorage(null)) .map(cap -> (int) ((float) cap.getEnergyStored() / (float) cap.getMaxEnergyStored() * 15F)) .orElse(0); } @@ -156,7 +156,7 @@ public class TileEntityBatteryBox extends TileEntityInventoryBase implements ISh @Override public int getEnergyToSplitShare() { - return this.getEnergyStorage(null) + return Optional.ofNullable(this.getEnergyStorage(null)) .map(IEnergyStorage::getEnergyStored) .orElse(0); } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBioReactor.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBioReactor.java index 1eaa879e9..26cf0f1d9 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBioReactor.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBioReactor.java @@ -31,9 +31,8 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.BonemealableBlock; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.common.IPlantable; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.energy.IEnergyStorage; +import net.neoforged.neoforge.common.IPlantable; +import net.neoforged.neoforge.energy.IEnergyStorage; import javax.annotation.Nullable; import java.util.ArrayList; @@ -42,7 +41,6 @@ import java.util.List; public class TileEntityBioReactor extends TileEntityInventoryBase implements MenuProvider, ISharingEnergyProvider { public final CustomEnergyStorage storage = new CustomEnergyStorage(200000, 0, 800); - public final LazyOptional lazyEnergy = LazyOptional.of(() -> this.storage); public int burnTime; public int maxBurnTime; @@ -177,8 +175,8 @@ public class TileEntityBioReactor extends TileEntityInventoryBase implements Men } @Override - public LazyOptional getEnergyStorage(Direction facing) { - return this.lazyEnergy; + public IEnergyStorage getEnergyStorage(Direction facing) { + return this.storage; } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBreaker.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBreaker.java index ecdac1286..b8018c0a2 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBreaker.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBreaker.java @@ -13,7 +13,6 @@ package de.ellpeck.actuallyadditions.mod.tile; import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks; import de.ellpeck.actuallyadditions.mod.inventory.ContainerBreaker; import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor; -import de.ellpeck.actuallyadditions.mod.util.NetHandlerSpaghettiServer; import de.ellpeck.actuallyadditions.mod.util.StackUtil; import de.ellpeck.actuallyadditions.mod.util.WorldUtil; import net.minecraft.core.BlockPos; @@ -32,9 +31,9 @@ import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.common.util.FakePlayer; -import net.minecraftforge.common.util.FakePlayerFactory; -import net.minecraftforge.fluids.IFluidBlock; +import net.neoforged.neoforge.common.util.FakePlayer; +import net.neoforged.neoforge.common.util.FakePlayerFactory; +import net.neoforged.neoforge.fluids.IFluidBlock; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -107,9 +106,6 @@ public class TileEntityBreaker extends TileEntityInventoryBase implements MenuPr if (!this.isPlacer && blockToBreak != Blocks.AIR && !(blockToBreak instanceof IFluidBlock) && stateToBreak.getDestroySpeed(this.level, breakCoords) >= 0.0F) { List drops = Block.getDrops(stateToBreak, (ServerLevel) this.level, breakCoords, this.level.getBlockEntity(breakCoords)); FakePlayer fake = FakePlayerFactory.getMinecraft((ServerLevel) this.level); - if (fake.connection == null) { - fake.connection = new NetHandlerSpaghettiServer(fake); - } if (stateToBreak.canHarvestBlock(this.level, breakCoords, fake)) { //TODO might double check this is right mikey if (StackUtil.canAddAll(this.inv, drops, false)) { this.level.destroyBlock(breakCoords, false); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCanolaPress.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCanolaPress.java index e55cce3f3..84371cd24 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCanolaPress.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCanolaPress.java @@ -28,16 +28,16 @@ import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.RecipeHolder; 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.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.energy.IEnergyStorage; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.FluidType; -import net.minecraftforge.fluids.capability.IFluidHandler; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; +import net.neoforged.neoforge.energy.IEnergyStorage; +import net.neoforged.neoforge.fluids.FluidStack; +import net.neoforged.neoforge.fluids.FluidType; +import net.neoforged.neoforge.fluids.capability.IFluidHandler; import javax.annotation.Nullable; import java.util.Optional; @@ -47,10 +47,7 @@ public class TileEntityCanolaPress extends TileEntityInventoryBase implements Me public static final int ENERGY_USE = 35; private static final int TIME = 30; public final CustomEnergyStorage storage = new CustomEnergyStorage(40000, 100, 0); - public final LazyOptional lazyEnergy = LazyOptional.of(() -> this.storage); - public final OutputOnlyFluidTank tank = new OutputOnlyFluidTank(2 * FluidType.BUCKET_VOLUME); - public final LazyOptional lazyFluid = LazyOptional.of(() -> this.tank); public int currentProcessTime; private int lastEnergyStored; @@ -106,8 +103,9 @@ public class TileEntityCanolaPress extends TileEntityInventoryBase implements Me if (t instanceof TileEntityCanolaPress tile) { tile.serverTick(); - Optional recipe = getRecipeForInput(tile.inv.getStackInSlot(0)); - recipe.ifPresent(r -> { + Optional> recipe = getRecipeForInput(tile.inv.getStackInSlot(0)); + recipe.ifPresent(h -> { + PressingRecipe r = h.value(); if ((r.getOutput().isFluidEqual(tile.tank.getFluid()) || tile.tank.isEmpty()) && r.getOutput().getAmount() <= tile.tank.getCapacity() - tile.tank.getFluidAmount()) { if (tile.storage.getEnergyStored() >= ENERGY_USE) { tile.currentProcessTime++; @@ -138,8 +136,8 @@ public class TileEntityCanolaPress extends TileEntityInventoryBase implements Me return getRecipeForInput(stack).isPresent(); } - public static Optional getRecipeForInput(ItemStack stack) { - return ActuallyAdditionsAPI.PRESSING_RECIPES.stream().filter(recipe -> recipe.matches(new SingleItem(stack), null)).findFirst(); + public static Optional> getRecipeForInput(ItemStack stack) { + return ActuallyAdditionsAPI.PRESSING_RECIPES.stream().filter(recipe -> recipe.value().matches(new SingleItem(stack), null)).findFirst(); } @Override @@ -153,8 +151,8 @@ public class TileEntityCanolaPress extends TileEntityInventoryBase implements Me } @Override - public LazyOptional getFluidHandler(Direction facing) { - return this.lazyFluid; + public IFluidHandler getFluidHandler(Direction facing) { + return this.tank; } @Override @@ -173,8 +171,8 @@ public class TileEntityCanolaPress extends TileEntityInventoryBase implements Me } @Override - public LazyOptional getEnergyStorage(Direction facing) { - return this.lazyEnergy; + public IEnergyStorage getEnergyStorage(Direction facing) { + return this.storage; } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCoalGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCoalGenerator.java index 3ab329e85..d48196eb0 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCoalGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCoalGenerator.java @@ -27,28 +27,27 @@ import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.RecipeHolder; 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.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.common.ForgeHooks; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.energy.IEnergyStorage; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; +import net.neoforged.neoforge.common.CommonHooks; +import net.neoforged.neoforge.energy.IEnergyStorage; import javax.annotation.Nullable; public class TileEntityCoalGenerator extends TileEntityInventoryBase implements MenuProvider, ISharingEnergyProvider, IEnergyDisplay { public final CustomEnergyStorage storage = new CustomEnergyStorage(60000, 0, 80); - public final LazyOptional lazyEnergy = LazyOptional.of(() -> this.storage); public int maxBurnTime; public int currentBurnTime; private int lastEnergy; private int lastBurnTime; private int lastCurrentBurnTime; private int lastCompare; - private SolidFuelRecipe currentRecipe = null; + private RecipeHolder currentRecipe = null; public TileEntityCoalGenerator(BlockPos pos, BlockState state) { super(ActuallyBlocks.COAL_GENERATOR.getTileEntityType(), pos, state, 1); @@ -70,7 +69,7 @@ public class TileEntityCoalGenerator extends TileEntityInventoryBase implements compound.putInt("BurnTime", this.currentBurnTime); compound.putInt("MaxBurnTime", this.maxBurnTime); if (currentRecipe != null) - compound.putString("currentRecipe", currentRecipe.getId().toString()); + compound.putString("currentRecipe", currentRecipe.id().toString()); } this.storage.writeToNBT(compound); super.writeSyncableNBT(compound, type); @@ -83,8 +82,8 @@ public class TileEntityCoalGenerator extends TileEntityInventoryBase implements this.maxBurnTime = compound.getInt("MaxBurnTime"); if (compound.contains("currentRecipe")) { ResourceLocation id = new ResourceLocation(compound.getString("currentRecipe")); - for (SolidFuelRecipe fuelRecipe : ActuallyAdditionsAPI.SOLID_FUEL_RECIPES) { - if (fuelRecipe.getId().equals(id)) { + for (RecipeHolder fuelRecipe : ActuallyAdditionsAPI.SOLID_FUEL_RECIPES) { + if (fuelRecipe.id().equals(id)) { this.currentRecipe = fuelRecipe; break; } @@ -109,7 +108,7 @@ public class TileEntityCoalGenerator extends TileEntityInventoryBase implements if (tile.currentBurnTime > 0 && tile.currentRecipe != null) { tile.currentBurnTime--; - int produce = tile.currentRecipe.getTotalEnergy() / tile.currentRecipe.getBurnTime(); + int produce = tile.currentRecipe.value().getTotalEnergy() / tile.currentRecipe.value().getBurnTime(); if (produce > 0) { tile.storage.receiveEnergyInternal(produce, false); } @@ -118,9 +117,9 @@ public class TileEntityCoalGenerator extends TileEntityInventoryBase implements if (!tile.isRedstonePowered && tile.currentBurnTime <= 0 && tile.storage.getEnergyStored() < tile.storage.getMaxEnergyStored()) { ItemStack stack = tile.inv.getStackInSlot(0); if (!stack.isEmpty()) { - ActuallyAdditionsAPI.SOLID_FUEL_RECIPES.stream().filter(r -> r.matches(stack)).findFirst().ifPresent(recipe -> { + ActuallyAdditionsAPI.SOLID_FUEL_RECIPES.stream().filter(r -> r.value().matches(stack)).findFirst().ifPresent(recipe -> { tile.currentRecipe = recipe; - tile.maxBurnTime = recipe.getBurnTime(); + tile.maxBurnTime = recipe.value().getBurnTime(); tile.currentBurnTime = tile.maxBurnTime; tile.inv.setStackInSlot(0, StackUtil.shrinkForContainer(stack, 1)); }); @@ -150,8 +149,8 @@ public class TileEntityCoalGenerator extends TileEntityInventoryBase implements @Override public IAcceptor getAcceptor() { return (slot, stack, automation) -> { - for (SolidFuelRecipe recipe : ActuallyAdditionsAPI.SOLID_FUEL_RECIPES) { - if (recipe.matches(stack))return true; + for (RecipeHolder recipe : ActuallyAdditionsAPI.SOLID_FUEL_RECIPES) { + if (recipe.value().matches(stack))return true; } return false; }; @@ -163,7 +162,7 @@ public class TileEntityCoalGenerator extends TileEntityInventoryBase implements if (!automation) { return true; } - return ForgeHooks.getBurnTime(this.inv.getStackInSlot(0), null) <= 0; + return CommonHooks.getBurnTime(this.inv.getStackInSlot(0), null) <= 0; }; } @@ -188,8 +187,8 @@ public class TileEntityCoalGenerator extends TileEntityInventoryBase implements } @Override - public LazyOptional getEnergyStorage(Direction facing) { - return this.lazyEnergy; + public IEnergyStorage getEnergyStorage(Direction facing) { + return this.storage; } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCoffeeMachine.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCoffeeMachine.java index cc5b91063..e6d97bf04 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCoffeeMachine.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCoffeeMachine.java @@ -35,14 +35,13 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.Fluids; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.energy.IEnergyStorage; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.FluidType; -import net.minecraftforge.fluids.capability.IFluidHandler; -import net.minecraftforge.fluids.capability.templates.FluidTank; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; +import net.neoforged.neoforge.energy.IEnergyStorage; +import net.neoforged.neoforge.fluids.FluidStack; +import net.neoforged.neoforge.fluids.FluidType; +import net.neoforged.neoforge.fluids.capability.IFluidHandler; +import net.neoforged.neoforge.fluids.capability.templates.FluidTank; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -59,7 +58,6 @@ public class TileEntityCoffeeMachine extends TileEntityInventoryBase implements public static final int TIME_USED = 500; public final CustomEnergyStorage storage = new CustomEnergyStorage(300000, 250, 0); - public final LazyOptional lazyEnergy = LazyOptional.of(() -> this.storage); public final FluidTank tank = new FluidTank(4 * FluidType.BUCKET_VOLUME) { @Nonnull @@ -79,7 +77,6 @@ public class TileEntityCoffeeMachine extends TileEntityInventoryBase implements return fluid.getFluid() == Fluids.WATER; } }; - public final LazyOptional lazyTank = LazyOptional.of(() -> this.tank); public int coffeeCacheAmount; public int brewTime; @@ -225,8 +222,8 @@ public class TileEntityCoffeeMachine extends TileEntityInventoryBase implements } @Override - public LazyOptional getFluidHandler(Direction facing) { - return this.lazyTank; + public IFluidHandler getFluidHandler(Direction facing) { + return this.tank; } @Override @@ -245,8 +242,8 @@ public class TileEntityCoffeeMachine extends TileEntityInventoryBase implements } @Override - public LazyOptional getEnergyStorage(Direction facing) { - return this.lazyEnergy; + public IEnergyStorage getEnergyStorage(Direction facing) { + return this.storage; } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCompost.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCompost.java index 80f8ade57..5b7bcadc8 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCompost.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCompost.java @@ -81,9 +81,9 @@ // if (this.recipe != null) { // this.conversionTime++; // if (this.conversionTime >= COMPOST_TIME_TICKS) { -// ItemStack output = this.recipe.getOutput().copy(); -// output.setCount(input.getCount()); -// this.inv.setStackInSlot(0, output); +// ItemStack stack = this.recipe.getOutput().copy(); +// stack.setCount(input.getCount()); +// this.inv.setStackInSlot(0, stack); // this.conversionTime = 0; // this.markDirty(); // } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCrusher.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCrusher.java index af0f05012..5edc2d516 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCrusher.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCrusher.java @@ -29,13 +29,13 @@ import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.RecipeHolder; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.properties.BlockStateProperties; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.energy.IEnergyStorage; +import net.neoforged.neoforge.energy.IEnergyStorage; import javax.annotation.Nullable; import java.util.Optional; @@ -50,7 +50,6 @@ public class TileEntityCrusher extends TileEntityInventoryBase implements IButto public static final int SLOT_OUTPUT_2_2 = 5; public static final int ENERGY_USE = 40; public final CustomEnergyStorage storage = new CustomEnergyStorage(60000, 100, 0); - public final LazyOptional lazyEnergy = LazyOptional.of(() -> this.storage); public int firstCrushTime; public int secondCrushTime; public boolean isDouble; @@ -193,17 +192,17 @@ public class TileEntityCrusher extends TileEntityInventoryBase implements IButto return (slot, automation) -> !automation || slot == SLOT_OUTPUT_1_1 || slot == SLOT_OUTPUT_1_2 || slot == SLOT_OUTPUT_2_1 || slot == SLOT_OUTPUT_2_2; } - public static Optional getRecipeForInput(ItemStack itemStack) { - return ActuallyAdditionsAPI.CRUSHER_RECIPES.stream().filter($ -> $.matches(itemStack)).findFirst(); + public static Optional> getRecipeForInput(ItemStack itemStack) { + return ActuallyAdditionsAPI.CRUSHER_RECIPES.stream().filter($ -> $.value().matches(itemStack)).findFirst(); } public boolean canCrushOn(int theInput, int theFirstOutput, int theSecondOutput) { ItemStack inputStack = this.inv.getStackInSlot(theInput); if (!inputStack.isEmpty()) { - Optional recipeOpt = getRecipeForInput(inputStack); + Optional> recipeOpt = getRecipeForInput(inputStack); if (!recipeOpt.isPresent()) { return false; } - CrushingRecipe recipe = recipeOpt.get(); + CrushingRecipe recipe = recipeOpt.get().value(); ItemStack outputOne = recipe.getOutputOne(); ItemStack outputTwo = recipe.getOutputTwo(); if (!outputOne.isEmpty()) { @@ -220,11 +219,11 @@ public class TileEntityCrusher extends TileEntityInventoryBase implements IButto } public void finishCrushing(int theInput, int theFirstOutput, int theSecondOutput) { - Optional recipeOpt = getRecipeForInput(this.inv.getStackInSlot(theInput)); + Optional> recipeOpt = getRecipeForInput(this.inv.getStackInSlot(theInput)); if (!recipeOpt.isPresent()) { return; } - CrushingRecipe recipe = recipeOpt.get(); + CrushingRecipe recipe = recipeOpt.get().value(); ItemStack outputOne = recipe.getOutputOne(); if (!outputOne.isEmpty()) { @@ -271,8 +270,8 @@ public class TileEntityCrusher extends TileEntityInventoryBase implements IButto } @Override - public LazyOptional getEnergyStorage(Direction facing) { - return this.lazyEnergy; + public IEnergyStorage getEnergyStorage(Direction facing) { + return this.storage; } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityDisplayStand.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityDisplayStand.java index 9e203ddfd..ef4c19a29 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityDisplayStand.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityDisplayStand.java @@ -23,13 +23,11 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.energy.IEnergyStorage; +import net.neoforged.neoforge.energy.IEnergyStorage; public class TileEntityDisplayStand extends TileEntityInventoryBase implements IEnergyDisplay { public final CustomEnergyStorage storage = new CustomEnergyStorage(80000, 1000, 0); - public final LazyOptional lazyEnergy = LazyOptional.of(() -> this.storage); private int oldEnergy; public TileEntityDisplayStand(BlockPos pos, BlockState state) { @@ -109,8 +107,8 @@ public class TileEntityDisplayStand extends TileEntityInventoryBase implements I } @Override - public LazyOptional getEnergyStorage(Direction facing) { - return this.lazyEnergy; + public IEnergyStorage getEnergyStorage(Direction facing) { + return this.storage; } public ItemStack getStack() { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEmpowerer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEmpowerer.java index 2dac0afa4..e645a5f9c 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEmpowerer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEmpowerer.java @@ -23,20 +23,21 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.RecipeHolder; 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.server.ServerLifecycleHooks; +import net.neoforged.neoforge.server.ServerLifecycleHooks; import javax.annotation.Nullable; public class TileEntityEmpowerer extends TileEntityInventoryBase { public int processTime; - private EmpowererRecipe currentRecipe = null; - private EmpowererRecipe lastRecipe = null; + private RecipeHolder currentRecipe = null; + private RecipeHolder lastRecipe = null; - public EmpowererRecipe getCurrentRecipe(){ + public RecipeHolder getCurrentRecipe(){ return this.currentRecipe; } @@ -45,8 +46,8 @@ public class TileEntityEmpowerer extends TileEntityInventoryBase { } public static boolean isPossibleInput(ItemStack stack) { - for (EmpowererRecipe r : ServerLifecycleHooks.getCurrentServer().getRecipeManager().getAllRecipesFor(ActuallyRecipes.Types.EMPOWERING.get())) { - if (r.getInput().test(stack)) { + for (RecipeHolder r : ServerLifecycleHooks.getCurrentServer().getRecipeManager().getAllRecipesFor(ActuallyRecipes.Types.EMPOWERING.get())) { + if (r.value().getInput().test(stack)) { return true; } } @@ -54,9 +55,9 @@ public class TileEntityEmpowerer extends TileEntityInventoryBase { } @Nullable - public static EmpowererRecipe findMatchingRecipe(ItemStack base, ItemStack stand1, ItemStack stand2, ItemStack stand3, ItemStack stand4) { - for (EmpowererRecipe r : ServerLifecycleHooks.getCurrentServer().getRecipeManager().getAllRecipesFor(ActuallyRecipes.Types.EMPOWERING.get())) { - if (r.matches(base, stand1, stand2, stand3, stand4)) { + public static RecipeHolder findMatchingRecipe(ItemStack base, ItemStack stand1, ItemStack stand2, ItemStack stand3, ItemStack stand4) { + for (RecipeHolder r : ServerLifecycleHooks.getCurrentServer().getRecipeManager().getAllRecipesFor(ActuallyRecipes.Types.EMPOWERING.get())) { + if (r.value().matches(base, stand1, stand2, stand3, stand4)) { return r; } } @@ -75,9 +76,10 @@ public class TileEntityEmpowerer extends TileEntityInventoryBase { TileEntityDisplayStand[] stands = tile.getNearbyStands(); if (stands != null) { - EmpowererRecipe recipe = findMatchingRecipe(tile.inv.getStackInSlot(0), stands[0].getStack(), stands[1].getStack(), stands[2].getStack(), stands[3].getStack()); - if (recipe != null) { - tile.currentRecipe = recipe; + RecipeHolder holder = findMatchingRecipe(tile.inv.getStackInSlot(0), stands[0].getStack(), stands[1].getStack(), stands[2].getStack(), stands[3].getStack()); + if (holder != null) { + tile.currentRecipe = holder; + EmpowererRecipe recipe = holder.value(); boolean hasPower = true; @@ -153,7 +155,7 @@ public class TileEntityEmpowerer extends TileEntityInventoryBase { } if (type == NBTType.SYNC) { if (this.currentRecipe != null) - compound.putString("CurrentRecipe", this.currentRecipe.getId().toString()); + compound.putString("CurrentRecipe", this.currentRecipe.id().toString()); else compound.putString("CurrentRecipe", ""); } @@ -168,8 +170,8 @@ public class TileEntityEmpowerer extends TileEntityInventoryBase { if (type == NBTType.SYNC && compound.contains("CurrentRecipe")) { if (!compound.getString("CurrentRecipe").isEmpty()) { ResourceLocation id = new ResourceLocation(compound.getString("CurrentRecipe")); - for (EmpowererRecipe empowererRecipe : ActuallyAdditionsAPI.EMPOWERER_RECIPES) { - if (empowererRecipe.getId().equals(id)) { + for (RecipeHolder empowererRecipe : ActuallyAdditionsAPI.EMPOWERER_RECIPES) { + if (empowererRecipe.id().equals(id)) { this.currentRecipe = empowererRecipe; break; } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEnergizer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEnergizer.java index 2512e040f..665fbac47 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEnergizer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEnergizer.java @@ -27,16 +27,15 @@ import net.minecraft.world.item.enchantment.EnchantmentHelper; 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.ForgeCapabilities; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.energy.IEnergyStorage; +import net.neoforged.neoforge.capabilities.Capabilities; +import net.neoforged.neoforge.energy.IEnergyStorage; import javax.annotation.Nullable; +import java.util.Optional; public class TileEntityEnergizer extends TileEntityInventoryBase implements MenuProvider { public final CustomEnergyStorage storage = new CustomEnergyStorage(50000, 1000, 0); - public final LazyOptional lazyEnergy = LazyOptional.of(() -> this.storage); private int lastEnergy; public TileEntityEnergizer(BlockPos pos, BlockState state) { @@ -67,8 +66,10 @@ public class TileEntityEnergizer extends TileEntityInventoryBase implements Menu if (StackUtil.isValid(tile.inv.getStackInSlot(0)) && !StackUtil.isValid(tile.inv.getStackInSlot(1))) { if (tile.storage.getEnergyStored() > 0) { - int received = tile.inv.getStackInSlot(0).getCapability(ForgeCapabilities.ENERGY, null).map(cap -> cap.receiveEnergy(tile.storage.getEnergyStored(), false)).orElse(0); - boolean canTakeUp = tile.inv.getStackInSlot(0).getCapability(ForgeCapabilities.ENERGY, null).map(cap -> cap.getEnergyStored() >= cap.getMaxEnergyStored()).orElse(false); + Optional capability = Optional.ofNullable(tile.inv.getStackInSlot(0).getCapability(Capabilities.EnergyStorage.ITEM, null)); + + int received = capability.map(cap -> cap.receiveEnergy(tile.storage.getEnergyStored(), false)).orElse(0); + boolean canTakeUp = capability.map(cap -> cap.getEnergyStored() >= cap.getMaxEnergyStored()).orElse(false); if (received > 0) { tile.storage.extractEnergyInternal(received, false); @@ -89,7 +90,7 @@ public class TileEntityEnergizer extends TileEntityInventoryBase implements Menu @Override public IAcceptor getAcceptor() { - return (slot, stack, automation) -> !automation || slot == 0 && stack.getCapability(ForgeCapabilities.ENERGY, null).isPresent(); + return (slot, stack, automation) -> !automation || slot == 0 && stack.getCapability(Capabilities.EnergyStorage.ITEM, null) != null; } @Override @@ -102,8 +103,8 @@ public class TileEntityEnergizer extends TileEntityInventoryBase implements Menu } @Override - public LazyOptional getEnergyStorage(Direction facing) { - return this.lazyEnergy; + public IEnergyStorage getEnergyStorage(Direction facing) { + return this.storage; } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEnervator.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEnervator.java index 4f345f30b..552e42d55 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEnervator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEnervator.java @@ -26,16 +26,15 @@ import net.minecraft.world.inventory.AbstractContainerMenu; 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.ForgeCapabilities; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.energy.IEnergyStorage; +import net.neoforged.neoforge.capabilities.Capabilities; +import net.neoforged.neoforge.energy.IEnergyStorage; import javax.annotation.Nullable; +import java.util.Optional; public class TileEntityEnervator extends TileEntityInventoryBase implements ISharingEnergyProvider, MenuProvider { public final CustomEnergyStorage storage = new CustomEnergyStorage(50000, 0, 1000); - public final LazyOptional lazyEnergy = LazyOptional.of(() -> this.storage); private int lastEnergy; public TileEntityEnervator(BlockPos pos, BlockState state) { @@ -66,7 +65,7 @@ public class TileEntityEnervator extends TileEntityInventoryBase implements ISha if (StackUtil.isValid(tile.inv.getStackInSlot(0)) && !StackUtil.isValid(tile.inv.getStackInSlot(1))) { if (tile.storage.getEnergyStored() < tile.storage.getMaxEnergyStored()) { - LazyOptional capability = tile.inv.getStackInSlot(0).getCapability(ForgeCapabilities.ENERGY, null); + Optional capability = Optional.ofNullable(tile.inv.getStackInSlot(0).getCapability(Capabilities.EnergyStorage.ITEM, null)); int maxExtract = tile.storage.getMaxEnergyStored() - tile.storage.getEnergyStored(); int extracted = capability.map(cap -> cap.extractEnergy(maxExtract, false)).orElse(0); @@ -91,7 +90,7 @@ public class TileEntityEnervator extends TileEntityInventoryBase implements ISha @Override public IAcceptor getAcceptor() { - return (slot, stack, automation) -> !automation || slot == 0 && stack.getCapability(ForgeCapabilities.ENERGY, null).isPresent(); + return (slot, stack, automation) -> !automation || slot == 0 && stack.getCapability(Capabilities.EnergyStorage.ITEM, null) != null; } @Override @@ -124,8 +123,8 @@ public class TileEntityEnervator extends TileEntityInventoryBase implements ISha } @Override - public LazyOptional getEnergyStorage(Direction facing) { - return this.lazyEnergy; + public IEnergyStorage getEnergyStorage(Direction facing) { + return this.storage; } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFarmer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFarmer.java index caee49e52..c4d7711bc 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFarmer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFarmer.java @@ -35,8 +35,7 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.properties.BlockStateProperties; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.energy.IEnergyStorage; +import net.neoforged.neoforge.energy.IEnergyStorage; import javax.annotation.Nullable; import java.util.ArrayList; @@ -47,7 +46,6 @@ public class TileEntityFarmer extends TileEntityInventoryBase implements IFarmer private static final List SORTED_FARMER_BEHAVIORS = new ArrayList<>(); public final CustomEnergyStorage storage = new CustomEnergyStorage(100000, 1000, 0); - public final LazyOptional lazyEnergy = LazyOptional.of(() -> this.storage); private int waitTime; private int checkX; private int checkY; @@ -177,8 +175,8 @@ public class TileEntityFarmer extends TileEntityInventoryBase implements IFarmer } @Override - public LazyOptional getEnergyStorage(Direction facing) { - return this.lazyEnergy; + public IEnergyStorage getEnergyStorage(Direction facing) { + return this.storage; } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFermentingBarrel.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFermentingBarrel.java index d35bb7b53..3b7eb02ff 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFermentingBarrel.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFermentingBarrel.java @@ -22,16 +22,16 @@ import net.minecraft.world.MenuProvider; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.item.crafting.RecipeHolder; 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.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.FluidType; -import net.minecraftforge.fluids.capability.IFluidHandler; -import net.minecraftforge.fluids.capability.templates.FluidTank; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; +import net.neoforged.neoforge.fluids.FluidStack; +import net.neoforged.neoforge.fluids.FluidType; +import net.neoforged.neoforge.fluids.capability.IFluidHandler; +import net.neoforged.neoforge.fluids.capability.templates.FluidTank; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -39,14 +39,13 @@ import java.util.Optional; public class TileEntityFermentingBarrel extends TileEntityBase implements ISharingFluidHandler, MenuProvider { public final FermentingBarrelMultiTank tanks = new FermentingBarrelMultiTank(); - public final LazyOptional fluidOptional = LazyOptional.of(()->tanks); public int currentProcessTime; private int lastInput; private int lastOutput; private int lastProcessTime; private int lastCompare; - private FermentingRecipe currentRecipe; + private RecipeHolder currentRecipe; public TileEntityFermentingBarrel(BlockPos pos, BlockState state) { super(ActuallyBlocks.FERMENTING_BARREL.getTileEntityType(), pos, state); @@ -57,7 +56,7 @@ public class TileEntityFermentingBarrel extends TileEntityBase implements IShari compound.putInt("ProcessTime", this.currentProcessTime); compound.put("tanks", tanks.writeNBT()); if (currentRecipe != null) - compound.putString("currentRecipe", currentRecipe.getId().toString()); + compound.putString("currentRecipe", currentRecipe.id().toString()); super.writeSyncableNBT(compound, type); } @@ -68,7 +67,7 @@ public class TileEntityFermentingBarrel extends TileEntityBase implements IShari tanks.readNBT(compound.getCompound("tanks")); } if (compound.contains("currentRecipe")) { - this.currentRecipe = ActuallyAdditionsAPI.FERMENTING_RECIPES.stream().filter(recipe -> recipe.getId().toString().equals(compound.getString("currentRecipe"))).findFirst().orElse(null); + this.currentRecipe = ActuallyAdditionsAPI.FERMENTING_RECIPES.stream().filter(recipe -> recipe.id().toString().equals(compound.getString("currentRecipe"))).findFirst().orElse(null); } super.readSyncableNBT(compound, type); } @@ -86,19 +85,20 @@ public class TileEntityFermentingBarrel extends TileEntityBase implements IShari if (tile.currentRecipe == null) { //No recipe currently selected, check for one every 20 ticks if (tile.ticksElapsed % 20 == 0) - tile.currentRecipe = ActuallyAdditionsAPI.FERMENTING_RECIPES.stream().filter(recipe -> recipe.matches(tile.tanks.getFluidInTank(0), tile.tanks.getFluidInTank(1))).findFirst().orElse(null); + tile.currentRecipe = ActuallyAdditionsAPI.FERMENTING_RECIPES.stream().filter(recipe -> recipe.value().matches(tile.tanks.getFluidInTank(0), tile.tanks.getFluidInTank(1))).findFirst().orElse(null); } else { - if (tile.tanks.getFluidInTank(0).getAmount() >= tile.currentRecipe.getInput().getAmount() && - tile.tanks.getFluidInTank(0).getFluid().isSame(tile.currentRecipe.getInput().getFluid()) && - (tile.tanks.getFluidInTank(1).getFluid().isSame(tile.currentRecipe.getOutput().getFluid()) || tile.tanks.getFluidInTank(1).isEmpty()) && - tile.currentRecipe.getOutput().getAmount() <= tile.tanks.getTankCapacity(1) - tile.tanks.getFluidInTank(1).getAmount()) { + FermentingRecipe recipe = tile.currentRecipe.value(); + if (tile.tanks.getFluidInTank(0).getAmount() >= recipe.getInput().getAmount() && + tile.tanks.getFluidInTank(0).getFluid().isSame(recipe.getInput().getFluid()) && + (tile.tanks.getFluidInTank(1).getFluid().isSame(recipe.getOutput().getFluid()) || tile.tanks.getFluidInTank(1).isEmpty()) && + recipe.getOutput().getAmount() <= tile.tanks.getTankCapacity(1) - tile.tanks.getFluidInTank(1).getAmount()) { tile.currentProcessTime++; - if (tile.currentProcessTime >= tile.currentRecipe.getTime()) { + if (tile.currentProcessTime >= recipe.getTime()) { tile.currentProcessTime = 0; - tile.tanks.outputTank.fill(tile.currentRecipe.getOutput().copy(), IFluidHandler.FluidAction.EXECUTE); - tile.tanks.inputTank.getFluid().shrink(tile.currentRecipe.getInput().getAmount()); + tile.tanks.outputTank.fill(recipe.getOutput().copy(), IFluidHandler.FluidAction.EXECUTE); + tile.tanks.inputTank.getFluid().shrink(recipe.getInput().getAmount()); } } else { tile.currentProcessTime = 0; @@ -129,7 +129,7 @@ public class TileEntityFermentingBarrel extends TileEntityBase implements IShari @OnlyIn(Dist.CLIENT) public int getProcessScaled(int i) { if (currentRecipe != null) - return this.currentProcessTime * i / currentRecipe.getTime(); + return this.currentProcessTime * i / currentRecipe.value().getTime(); else return this.currentProcessTime * i / 100; } @@ -145,8 +145,8 @@ public class TileEntityFermentingBarrel extends TileEntityBase implements IShari } @Override - public LazyOptional getFluidHandler(Direction facing) { - return fluidOptional; + public IFluidHandler getFluidHandler(Direction facing) { + return tanks; } @Override @@ -180,8 +180,8 @@ public class TileEntityFermentingBarrel extends TileEntityBase implements IShari return getRecipeForInput(stack).isPresent(); } - public static Optional getRecipeForInput(FluidStack stack) { - return ActuallyAdditionsAPI.FERMENTING_RECIPES.stream().filter(recipe -> recipe.matches(stack)).findFirst(); + public static Optional> getRecipeForInput(FluidStack stack) { + return ActuallyAdditionsAPI.FERMENTING_RECIPES.stream().filter(recipe -> recipe.value().matches(stack)).findFirst(); } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFireworkBox.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFireworkBox.java index 306371e64..0dd462531 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFireworkBox.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFireworkBox.java @@ -33,8 +33,7 @@ import net.minecraft.world.item.Items; 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.util.LazyOptional; -import net.minecraftforge.energy.IEnergyStorage; +import net.neoforged.neoforge.energy.IEnergyStorage; import javax.annotation.Nullable; import java.util.ArrayList; @@ -44,7 +43,6 @@ public class TileEntityFireworkBox extends TileEntityBase implements IEnergyDisp public static final int USE_PER_SHOT = 500; public final CustomEnergyStorage storage = new CustomEnergyStorage(20000, 200, 0); - public final LazyOptional lazyEnergy = LazyOptional.of(() -> this.storage); public int intValuePlay = 2; public int chargeAmount = 2; public int flightTime = 2; @@ -289,8 +287,8 @@ public class TileEntityFireworkBox extends TileEntityBase implements IEnergyDisp } @Override - public LazyOptional getEnergyStorage(Direction facing) { - return this.lazyEnergy; + public IEnergyStorage getEnergyStorage(Direction facing) { + return this.storage; } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFluidCollector.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFluidCollector.java index 276dd8bbf..819a076bc 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFluidCollector.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFluidCollector.java @@ -34,11 +34,11 @@ import net.minecraft.world.level.block.LiquidBlock; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.FluidType; -import net.minecraftforge.fluids.IFluidBlock; -import net.minecraftforge.fluids.capability.IFluidHandler; +import net.neoforged.neoforge.common.util.LazyOptional; +import net.neoforged.neoforge.fluids.FluidStack; +import net.neoforged.neoforge.fluids.FluidType; +import net.neoforged.neoforge.fluids.IFluidBlock; +import net.neoforged.neoforge.fluids.capability.IFluidHandler; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -146,7 +146,7 @@ public class TileEntityFluidCollector extends TileEntityBase implements ISharing } @Override - public LazyOptional getFluidHandler(Direction facing) { + public IFluidHandler getFluidHandler(Direction facing) { return this.lazyTank; } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFurnaceSolar.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFurnaceSolar.java index 9a0831317..f13c40124 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFurnaceSolar.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFurnaceSolar.java @@ -112,7 +112,7 @@ // } // // @Override -// public LazyOptional getEnergyStorage(Direction facing) { +// public IEnergyStorage getEnergyStorage(Direction facing) { // return this.lazyEnergy; // } //} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityHeatCollector.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityHeatCollector.java index e19c70343..dcebcf24b 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityHeatCollector.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityHeatCollector.java @@ -22,8 +22,8 @@ import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.MagmaBlock; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.energy.IEnergyStorage; +import net.neoforged.neoforge.common.util.LazyOptional; +import net.neoforged.neoforge.energy.IEnergyStorage; import java.util.ArrayList; @@ -32,7 +32,6 @@ public class TileEntityHeatCollector extends TileEntityBase implements ISharingE public static final int ENERGY_PRODUCE = 40; public static final int BLOCKS_NEEDED = 4; public final CustomEnergyStorage storage = new CustomEnergyStorage(30000, 0, 80); - public final LazyOptional lazyEnergy = LazyOptional.of(() -> this.storage); private int oldEnergy; private int disappearTime; @@ -134,8 +133,8 @@ public class TileEntityHeatCollector extends TileEntityBase implements ISharingE } @Override - public LazyOptional getEnergyStorage(Direction facing) { - return this.lazyEnergy; + public IEnergyStorage getEnergyStorage(Direction facing) { + return this.storage; } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityInventoryBase.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityInventoryBase.java index e8d891834..32af3508d 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityInventoryBase.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityInventoryBase.java @@ -21,20 +21,17 @@ import net.minecraft.nbt.ListTag; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.items.IItemHandler; -import net.minecraftforge.items.IItemHandlerModifiable; -import net.minecraftforge.items.ItemHandlerHelper; +import net.neoforged.neoforge.items.IItemHandler; +import net.neoforged.neoforge.items.IItemHandlerModifiable; +import net.neoforged.neoforge.items.ItemHandlerHelper; public abstract class TileEntityInventoryBase extends TileEntityBase { public final ItemStackHandlerAA inv; - public final LazyOptional lazyInv; public TileEntityInventoryBase(BlockEntityType type, BlockPos pos, BlockState state, int slots) { super(type, pos, state); this.inv = new TileStackHandler(slots); - this.lazyInv = LazyOptional.of(() -> this.inv); } public static void saveSlots(IItemHandler slots, CompoundTag compound) { @@ -73,8 +70,8 @@ public abstract class TileEntityInventoryBase extends TileEntityBase { } @Override - public LazyOptional getItemHandler(Direction facing) { - return this.lazyInv; + public IItemHandler getItemHandler(Direction facing) { + return this.inv; } public IAcceptor getAcceptor() { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityItemInterface.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityItemInterface.java index ff36c575f..4cbb46ac6 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityItemInterface.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityItemInterface.java @@ -27,17 +27,15 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.items.IItemHandler; +import net.neoforged.neoforge.items.IItemHandler; import javax.annotation.Nonnull; -import javax.annotation.Nullable; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; public class TileEntityItemInterface extends TileEntityBase { @@ -45,7 +43,6 @@ public class TileEntityItemInterface extends TileEntityBase { public final Map itemHandlerInfos = new HashMap<>(); public final List slotlessInfos = new ArrayList<>(); protected final SlotlessableItemHandlerWrapper itemHandler; - private final LazyOptional lazyHandlers; public TileEntityLaserRelayItem connectedRelay; private int lastNetworkChangeAmount = -1; private int slotCount; @@ -120,8 +117,7 @@ public class TileEntityItemInterface extends TileEntityBase { // slotlessHandler = CommonCapsUtil.createSlotlessItemViewerHandler(this, normalHandler); // } - this.lazyHandlers = LazyOptional.of(() -> normalHandler); - this.itemHandler = new SlotlessableItemHandlerWrapper(this.lazyHandlers, slotlessHandler); + this.itemHandler = new SlotlessableItemHandlerWrapper(normalHandler, slotlessHandler); } public TileEntityItemInterface(BlockPos pos, BlockState state) { @@ -141,16 +137,10 @@ public class TileEntityItemInterface extends TileEntityBase { } @Override - public LazyOptional getItemHandler(Direction facing) { + public IItemHandler getItemHandler(Direction facing) { return this.itemHandler.getNormalHandler(); } - @Nonnull - @Override - public LazyOptional getCapability(@Nonnull Capability capability, @Nullable Direction side) { - return super.getCapability(capability, side); - } - // TODO: [port] Maybe add back // @SuppressWarnings("unchecked") // @Override @@ -188,7 +178,7 @@ public class TileEntityItemInterface extends TileEntityBase { for (Player player : this.level.players()) { if (player instanceof ServerPlayer) { if (player.distanceToSqr(input.getX(), input.getY(), input.getZ()) <= rangeSq || player.distanceToSqr(output.getX(), output.getY(), output.getZ()) <= rangeSq) { - PacketHandler.sendTo(new PacketServerToClient(compound, PacketHandler.LASER_PARTICLE_HANDLER), (ServerPlayer) player); + ((ServerPlayer) player).connection.send(new PacketServerToClient(compound, PacketHandler.LASER_PARTICLE_HANDLER)); } } } @@ -209,7 +199,7 @@ public class TileEntityItemInterface extends TileEntityBase { int slotsQueried = 0; for (GenericItemHandlerInfo info : this.genericInfos) { for (SlotlessableItemHandlerWrapper handler : info.handlers) { - LazyOptional normalHandler = handler.getNormalHandler(); + Optional normalHandler = Optional.ofNullable(handler.getNormalHandler()); slotsQueried += normalHandler.map(cap -> { int queried = 0; for (int i = 0; i < cap.getSlots(); i++) { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityItemInterfaceHopping.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityItemInterfaceHopping.java index 7002bff80..ae7ed51ea 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityItemInterfaceHopping.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityItemInterfaceHopping.java @@ -26,9 +26,9 @@ import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.phys.AABB; -import net.minecraftforge.common.capabilities.ForgeCapabilities; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.items.IItemHandler; +import net.neoforged.neoforge.common.capabilities.Capabilities; +import net.neoforged.neoforge.common.util.LazyOptional; +import net.neoforged.neoforge.items.IItemHandler; import java.util.List; @@ -111,7 +111,7 @@ public class TileEntityItemInterfaceHopping extends TileEntityItemInterface { BlockEntity from = this.level.getBlockEntity(this.getBlockPos().relative(Direction.UP)); if (from != null && !(from instanceof TileEntityItemInterface)) { - LazyOptional normal = from.getCapability(ForgeCapabilities.ITEM_HANDLER, Direction.DOWN); + LazyOptional normal = from.getCapability(Capabilities.ITEM_HANDLER, Direction.DOWN); Object slotless = null; // TODO: [port] add back @@ -132,7 +132,7 @@ public class TileEntityItemInterfaceHopping extends TileEntityItemInterface { if (this.level.isLoaded(toPos)) { BlockEntity to = this.level.getBlockEntity(toPos); if (to != null && !(to instanceof TileEntityItemInterface)) { - LazyOptional normal = to.getCapability(ForgeCapabilities.ITEM_HANDLER, facing.getOpposite()); + LazyOptional normal = to.getCapability(Capabilities.ITEM_HANDLER, facing.getOpposite()); Object slotless = null; // TODO: [port] Add back diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelay.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelay.java index 552e9ff85..603478ddc 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelay.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelay.java @@ -26,11 +26,9 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.phys.AABB; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.items.IItemHandler; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; +import net.neoforged.neoforge.items.IItemHandler; public abstract class TileEntityLaserRelay extends TileEntityInventoryBase { @@ -176,11 +174,11 @@ public abstract class TileEntityLaserRelay extends TileEntityInventoryBase { return this.cachedNetwork; } - @Override - @OnlyIn(Dist.CLIENT) - public AABB getRenderBoundingBox() { - return INFINITE_EXTENT_AABB; - } +// @Override TODO: Fix the renderBoundingBox +// @OnlyIn(Dist.CLIENT) +// public AABB getRenderBoundingBox() { +// return INFINITE_EXTENT_AABB; +// } @Override public boolean shouldSyncSlots() { @@ -188,8 +186,8 @@ public abstract class TileEntityLaserRelay extends TileEntityInventoryBase { } @Override - public LazyOptional getItemHandler(Direction facing) { - return LazyOptional.empty(); + public IItemHandler getItemHandler(Direction facing) { + return null; } public int getMaxRange() { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayEnergy.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayEnergy.java index bbd51b46e..04c7c712e 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayEnergy.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayEnergy.java @@ -28,11 +28,11 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.common.capabilities.ForgeCapabilities; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.energy.IEnergyStorage; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; +import net.neoforged.neoforge.common.capabilities.Capabilities; +import net.neoforged.neoforge.common.util.LazyOptional; +import net.neoforged.neoforge.energy.IEnergyStorage; import java.util.HashMap; import java.util.Map; @@ -114,7 +114,7 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay { // TODO: [port] this is super hacky, review and fix up @Override - public LazyOptional getEnergyStorage(Direction facing) { + public IEnergyStorage getEnergyStorage(Direction facing) { return LazyOptional.of(() -> this.energyStorages[facing == null ? 0 : facing.ordinal()]); @@ -136,7 +136,7 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay { if (this.level.hasChunkAt(pos)) { BlockEntity tile = this.level.getBlockEntity(pos); if (tile != null && !(tile instanceof TileEntityLaserRelay)) { - if (tile.getCapability(ForgeCapabilities.ENERGY, side.getOpposite()).isPresent()) { + if (tile.getCapability(Capabilities.ENERGY, side.getOpposite()).isPresent()) { this.receiversAround.put(side, tile); BlockEntity oldTile = old.get(side); @@ -179,7 +179,7 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay { Direction opp = facing.getOpposite(); if (tile != null) { - Boolean received = tile.getCapability(ForgeCapabilities.ENERGY, opp).map(cap -> cap.receiveEnergy(maxTransfer, true) > 0).orElse(false); + Boolean received = tile.getCapability(Capabilities.ENERGY, opp).map(cap -> cap.receiveEnergy(maxTransfer, true) > 0).orElse(false); if (received) { totalReceiverAmount++; workedOnce = true; @@ -213,7 +213,7 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay { if (!alreadyChecked.contains(tile.getBlockPos())) { alreadyChecked.add(tile.getBlockPos()); if (theRelay != this || side != from) { - transmitted += tile.getCapability(ForgeCapabilities.ENERGY, opp).map(cap -> { + transmitted += tile.getCapability(Capabilities.ENERGY, opp).map(cap -> { int trans = 0; int theoreticalReceived = cap.receiveEnergy(Math.min(amountPer, lowestCap), true); if (theoreticalReceived > 0) { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayFluids.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayFluids.java index 871d39648..6299c9bf5 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayFluids.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayFluids.java @@ -26,12 +26,12 @@ import net.minecraft.world.entity.player.Player; 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.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.common.capabilities.ForgeCapabilities; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.capability.IFluidHandler; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; +import net.neoforged.neoforge.common.capabilities.Capabilities; +import net.neoforged.neoforge.common.util.LazyOptional; +import net.neoforged.neoforge.fluids.FluidStack; +import net.neoforged.neoforge.fluids.capability.IFluidHandler; import javax.annotation.Nonnull; import java.util.HashMap; @@ -133,7 +133,7 @@ public class TileEntityLaserRelayFluids extends TileEntityLaserRelay { if (this.level.hasChunkAt(pos)) { BlockEntity tile = this.level.getBlockEntity(pos); if (tile != null && !(tile instanceof TileEntityLaserRelay)) { - if (tile.getCapability(ForgeCapabilities.FLUID_HANDLER, side.getOpposite()).isPresent()) { + if (tile.getCapability(Capabilities.FLUID_HANDLER, side.getOpposite()).isPresent()) { this.handlersAround.put(side, tile); BlockEntity oldTile = old.get(side); @@ -155,7 +155,7 @@ public class TileEntityLaserRelayFluids extends TileEntityLaserRelay { // TODO: [port] super hacky, find better way of handling this. @Override - public LazyOptional getFluidHandler(Direction facing) { + public IFluidHandler getFluidHandler(Direction facing) { return LazyOptional.of(() -> this.fluidHandlers[facing == null ? 0 : facing.ordinal()]); @@ -194,7 +194,7 @@ public class TileEntityLaserRelayFluids extends TileEntityLaserRelay { BlockEntity tile = theRelay.handlersAround.get(facing); Direction opp = facing.getOpposite(); - boolean received = tile.getCapability(ForgeCapabilities.FLUID_HANDLER, opp).map(cap -> cap.fill(stack, IFluidHandler.FluidAction.SIMULATE) > 0).orElse(false); + boolean received = tile.getCapability(Capabilities.FLUID_HANDLER, opp).map(cap -> cap.fill(stack, IFluidHandler.FluidAction.SIMULATE) > 0).orElse(false); if (received) { totalReceiverAmount++; workedOnce = true; @@ -225,7 +225,7 @@ public class TileEntityLaserRelayFluids extends TileEntityLaserRelay { if (!alreadyChecked.contains(tile.getBlockPos())) { alreadyChecked.add(tile.getBlockPos()); if (theRelay != this || side != from) { - transmitted += tile.getCapability(ForgeCapabilities.FLUID_HANDLER, opp).map(cap -> { + transmitted += tile.getCapability(Capabilities.FLUID_HANDLER, opp).map(cap -> { int trans = 0; FluidStack copy = stack.copy(); copy.setAmount(amountPer); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayItem.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayItem.java index ca72429f4..b85bf4261 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayItem.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayItem.java @@ -29,11 +29,11 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.common.capabilities.ForgeCapabilities; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.items.IItemHandler; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; +import net.neoforged.neoforge.common.capabilities.Capabilities; +import net.neoforged.neoforge.common.util.LazyOptional; +import net.neoforged.neoforge.items.IItemHandler; import java.util.HashMap; import java.util.HashSet; @@ -92,7 +92,7 @@ public class TileEntityLaserRelayItem extends TileEntityLaserRelay { if (this.level.hasChunkAt(pos)) { BlockEntity tile = this.level.getBlockEntity(pos); if (tile != null && !(tile instanceof TileEntityItemInterface) && !(tile instanceof TileEntityLaserRelay)) { - LazyOptional itemHandler = tile.getCapability(ForgeCapabilities.ITEM_HANDLER, side.getOpposite()); + LazyOptional itemHandler = tile.getCapability(Capabilities.ITEM_HANDLER, side.getOpposite()); Object slotlessHandler = null; // TODO: [port] add this back maybe? diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLavaFactoryController.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLavaFactoryController.java index fdc8227f5..787f4737f 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLavaFactoryController.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLavaFactoryController.java @@ -20,8 +20,7 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.energy.IEnergyStorage; +import net.neoforged.neoforge.energy.IEnergyStorage; public class TileEntityLavaFactoryController extends TileEntityBase implements IEnergyDisplay { @@ -30,7 +29,6 @@ public class TileEntityLavaFactoryController extends TileEntityBase implements I public static final int HAS_AIR = 2; public static final int ENERGY_USE = 150000; public final CustomEnergyStorage storage = new CustomEnergyStorage(300000, 2000, 0); - public final LazyOptional lazyEnergy = LazyOptional.of(() -> this.storage); private int currentWorkTime; private int oldEnergy; @@ -113,7 +111,7 @@ public class TileEntityLavaFactoryController extends TileEntityBase implements I } @Override - public LazyOptional getEnergyStorage(Direction facing) { - return this.lazyEnergy; + public IEnergyStorage getEnergyStorage(Direction facing) { + return this.storage; } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLeafGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLeafGenerator.java index 94987a76a..5e4263222 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLeafGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLeafGenerator.java @@ -22,8 +22,8 @@ import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.LeavesBlock; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.energy.IEnergyStorage; +import net.neoforged.neoforge.common.util.LazyOptional; +import net.neoforged.neoforge.energy.IEnergyStorage; import java.util.ArrayList; import java.util.Collections; @@ -139,7 +139,7 @@ public class TileEntityLeafGenerator extends TileEntityBase implements ISharingE } @Override - public LazyOptional getEnergyStorage(Direction facing) { + public IEnergyStorage getEnergyStorage(Direction facing) { return this.lazyEnergy; } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLongRangeBreaker.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLongRangeBreaker.java index c6e4b7eeb..107324e79 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLongRangeBreaker.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLongRangeBreaker.java @@ -30,8 +30,8 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.energy.IEnergyStorage; +import net.neoforged.neoforge.common.util.LazyOptional; +import net.neoforged.neoforge.energy.IEnergyStorage; import javax.annotation.Nullable; import java.util.List; @@ -141,7 +141,7 @@ public class TileEntityLongRangeBreaker extends TileEntityInventoryBase implemen } @Override - public LazyOptional getEnergyStorage(Direction facing) { + public IEnergyStorage getEnergyStorage(Direction facing) { return this.lazyEnergy; } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityOilGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityOilGenerator.java index 120c14417..5cf78e177 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityOilGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityOilGenerator.java @@ -23,24 +23,23 @@ import net.minecraft.world.MenuProvider; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.item.crafting.RecipeHolder; 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.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.energy.IEnergyStorage; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.FluidType; -import net.minecraftforge.fluids.capability.IFluidHandler; -import net.minecraftforge.fluids.capability.templates.FluidTank; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; +import net.neoforged.neoforge.energy.IEnergyStorage; +import net.neoforged.neoforge.fluids.FluidStack; +import net.neoforged.neoforge.fluids.FluidType; +import net.neoforged.neoforge.fluids.capability.IFluidHandler; +import net.neoforged.neoforge.fluids.capability.templates.FluidTank; import javax.annotation.Nonnull; import javax.annotation.Nullable; public class TileEntityOilGenerator extends TileEntityBase implements ISharingEnergyProvider, ISharingFluidHandler, MenuProvider { public final CustomEnergyStorage storage = new CustomEnergyStorage(50000, 0, CommonConfig.Machines.OIL_GENERATOR_TRANSFER.get()); - public final LazyOptional lazyEnergy = LazyOptional.of(() -> this.storage); public final FluidTank tank = new FluidTank(2 * FluidType.BUCKET_VOLUME, fluid -> getRecipeForFluid(fluid) != null) { @Nonnull @Override @@ -54,7 +53,6 @@ public class TileEntityOilGenerator extends TileEntityBase implements ISharingEn return FluidStack.EMPTY; } }; - public final LazyOptional lazyTank = LazyOptional.of(() -> this.tank); public int currentEnergyProduce; public int currentBurnTime; public int maxBurnTime; @@ -70,10 +68,10 @@ public class TileEntityOilGenerator extends TileEntityBase implements ISharingEn super(ActuallyBlocks.OIL_GENERATOR.getTileEntityType(), pos, state); } - private static LiquidFuelRecipe getRecipeForFluid(FluidStack fluid) { + private static RecipeHolder getRecipeForFluid(FluidStack fluid) { if (fluid != null) { - for (LiquidFuelRecipe recipe : ActuallyAdditionsAPI.LIQUID_FUEL_RECIPES) { - if (recipe != null && recipe.matches(fluid)) { + for (RecipeHolder recipe : ActuallyAdditionsAPI.LIQUID_FUEL_RECIPES) { + if (recipe != null && recipe.value().matches(fluid)) { return recipe; } } @@ -86,7 +84,7 @@ public class TileEntityOilGenerator extends TileEntityBase implements ISharingEn return this.currentBurnTime * i / this.maxBurnTime; } - private LiquidFuelRecipe getRecipeForCurrentFluid() { + private RecipeHolder getRecipeForCurrentFluid() { FluidStack stack = this.tank.getFluid(); if (!stack.isEmpty()) { return getRecipeForFluid(stack); @@ -138,8 +136,9 @@ public class TileEntityOilGenerator extends TileEntityBase implements ISharingEn tile.storage.receiveEnergyInternal(tile.currentEnergyProduce, false); } else if (!tile.isRedstonePowered) { - LiquidFuelRecipe recipe = tile.getRecipeForCurrentFluid(); - if (recipe != null && tile.storage.getEnergyStored() < tile.storage.getMaxEnergyStored() && tile.tank.getFluidAmount() >= recipe.getFuelAmount()) { + RecipeHolder recipeHolder = tile.getRecipeForCurrentFluid(); + if (recipeHolder != null && tile.storage.getEnergyStored() < tile.storage.getMaxEnergyStored() && tile.tank.getFluidAmount() >= recipeHolder.getFuelAmount()) { + LiquidFuelRecipe recipe = recipeHolder.value(); tile.fuelUsage = recipe.getFuelAmount(); tile.currentEnergyProduce = recipe.getTotalEnergy() / recipe.getBurnTime(); tile.maxBurnTime = recipe.getBurnTime(); @@ -177,8 +176,8 @@ public class TileEntityOilGenerator extends TileEntityBase implements ISharingEn } @Override - public LazyOptional getFluidHandler(Direction facing) { - return this.lazyTank; + public IFluidHandler getFluidHandler(Direction facing) { + return this.tank; } @Override @@ -217,8 +216,8 @@ public class TileEntityOilGenerator extends TileEntityBase implements ISharingEn } @Override - public LazyOptional getEnergyStorage(Direction facing) { - return this.lazyEnergy; + public IEnergyStorage getEnergyStorage(Direction facing) { + return this.storage; } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomEnergyface.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomEnergyface.java index 1cce4763e..c0e0b91be 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomEnergyface.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomEnergyface.java @@ -17,8 +17,8 @@ import net.minecraft.core.Direction; 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.neoforged.neoforge.common.capabilities.Capabilities; +import net.neoforged.neoforge.common.capabilities.Capability; public class TileEntityPhantomEnergyface extends TileEntityPhantomface implements ISharingEnergyProvider { @@ -45,7 +45,7 @@ public class TileEntityPhantomEnergyface extends TileEntityPhantomface implement BlockEntity tile = this.level.getBlockEntity(this.boundPosition); if (tile != null && !(tile instanceof TileEntityLaserRelayEnergy)) { for (Direction facing : Direction.values()) { - if (tile.getCapability(ForgeCapabilities.ENERGY, facing).isPresent()) { + if (tile.getCapability(Capabilities.ENERGY, facing).isPresent()) { return true; } } @@ -56,7 +56,7 @@ public class TileEntityPhantomEnergyface extends TileEntityPhantomface implement @Override protected boolean isCapabilitySupported(Capability capability) { - return capability == ForgeCapabilities.ENERGY; + return capability == Capabilities.ENERGY; } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomItemface.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomItemface.java index 810a4c46b..ba7131ba7 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomItemface.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomItemface.java @@ -19,8 +19,8 @@ import net.minecraft.core.Direction; 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.neoforged.neoforge.common.capabilities.Capabilities; +import net.neoforged.neoforge.common.capabilities.Capability; public class TileEntityPhantomItemface extends TileEntityPhantomface { @@ -52,7 +52,7 @@ public class TileEntityPhantomItemface extends TileEntityPhantomface { BlockEntity tile = this.level.getBlockEntity(this.getBoundPosition()); if (tile != null) { for (Direction facing : Direction.values()) { - if (tile.getCapability(ForgeCapabilities.ITEM_HANDLER, facing).isPresent()) { + if (tile.getCapability(Capabilities.ITEM_HANDLER, facing).isPresent()) { return true; } } @@ -63,7 +63,7 @@ public class TileEntityPhantomItemface extends TileEntityPhantomface { @Override protected boolean isCapabilitySupported(Capability capability) { - return capability == ForgeCapabilities.ITEM_HANDLER; + return capability == Capabilities.ITEM_HANDLER; } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomLiquiface.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomLiquiface.java index 0bf693d26..12185f52c 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomLiquiface.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomLiquiface.java @@ -17,8 +17,8 @@ import net.minecraft.core.Direction; 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.neoforged.neoforge.common.capabilities.Capabilities; +import net.neoforged.neoforge.common.capabilities.Capability; public class TileEntityPhantomLiquiface extends TileEntityPhantomface implements ISharingFluidHandler { @@ -45,7 +45,7 @@ public class TileEntityPhantomLiquiface extends TileEntityPhantomface implements BlockEntity tile = this.level.getBlockEntity(this.boundPosition); if (tile != null && !(tile instanceof TileEntityLaserRelayFluids)) { for (Direction facing : Direction.values()) { - if (tile.getCapability(ForgeCapabilities.FLUID_HANDLER, facing).isPresent()) { + if (tile.getCapability(Capabilities.FLUID_HANDLER, facing).isPresent()) { return true; } } @@ -56,7 +56,7 @@ public class TileEntityPhantomLiquiface extends TileEntityPhantomface implements @Override protected boolean isCapabilitySupported(Capability capability) { - return capability == ForgeCapabilities.FLUID_HANDLER; + return capability == Capabilities.FLUID_HANDLER; } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomRedstoneface.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomRedstoneface.java index d266e0b13..0c63ca29a 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomRedstoneface.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomRedstoneface.java @@ -17,7 +17,7 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.common.capabilities.Capability; +import net.neoforged.neoforge.common.capabilities.Capability; import java.util.Arrays; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomface.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomface.java index ee832905f..3dbf4405b 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomface.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomface.java @@ -22,10 +22,10 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.common.util.LazyOptional; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; +import net.neoforged.neoforge.common.capabilities.Capability; +import net.neoforged.neoforge.common.util.LazyOptional; import javax.annotation.Nonnull; import javax.annotation.Nullable; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPlayerInterface.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPlayerInterface.java index 686bb0c40..92777175e 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPlayerInterface.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPlayerInterface.java @@ -20,11 +20,11 @@ import net.minecraft.world.item.ItemStack; 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.ForgeCapabilities; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.energy.IEnergyStorage; -import net.minecraftforge.items.IItemHandler; -import net.minecraftforge.items.wrapper.PlayerInvWrapper; +import net.neoforged.neoforge.common.capabilities.Capabilities; +import net.neoforged.neoforge.common.util.LazyOptional; +import net.neoforged.neoforge.energy.IEnergyStorage; +import net.neoforged.neoforge.items.IItemHandler; +import net.neoforged.neoforge.items.wrapper.PlayerInvWrapper; import java.util.UUID; @@ -58,7 +58,7 @@ public class TileEntityPlayerInterface extends TileEntityBase implements IEnergy // TODO: [port] this might not be a stable way of doing this. @Override - public LazyOptional getItemHandler(Direction facing) { + public IItemHandler getItemHandler(Direction facing) { Player player = this.getPlayer(); if (this.oldPlayer != player) { @@ -93,7 +93,7 @@ public class TileEntityPlayerInterface extends TileEntityBase implements IEnergy ItemStack slot = player.getInventory().getItem(i); if (StackUtil.isValid(slot) && slot.getCount() == 1) { - int received = slot.getCapability(ForgeCapabilities.ENERGY).map(cap -> cap.receiveEnergy(tile.storage.getEnergyStored(), false)).orElse(0); + int received = slot.getCapability(Capabilities.ENERGY).map(cap -> cap.receiveEnergy(tile.storage.getEnergyStored(), false)).orElse(0); if (received > 0) { tile.storage.extractEnergyInternal(received, false); } @@ -148,7 +148,7 @@ public class TileEntityPlayerInterface extends TileEntityBase implements IEnergy } @Override - public LazyOptional getEnergyStorage(Direction facing) { + public IEnergyStorage getEnergyStorage(Direction facing) { return this.lazyEnergy; } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPoweredFurnace.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPoweredFurnace.java index 5d0ce9930..ea7806ef1 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPoweredFurnace.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPoweredFurnace.java @@ -34,8 +34,8 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.properties.BlockStateProperties; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.energy.IEnergyStorage; +import net.neoforged.neoforge.common.util.LazyOptional; +import net.neoforged.neoforge.energy.IEnergyStorage; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -249,7 +249,7 @@ public class TileEntityPoweredFurnace extends TileEntityInventoryBase implements } @Override - public LazyOptional getEnergyStorage(Direction facing) { + public IEnergyStorage getEnergyStorage(Direction facing) { return this.lazyEnergy; } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityShockSuppressor.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityShockSuppressor.java index 274a037a5..5bf4707c7 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityShockSuppressor.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityShockSuppressor.java @@ -17,8 +17,8 @@ import net.minecraft.nbt.CompoundTag; 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.util.LazyOptional; -import net.minecraftforge.energy.IEnergyStorage; +import net.neoforged.neoforge.common.util.LazyOptional; +import net.neoforged.neoforge.energy.IEnergyStorage; import java.util.ArrayList; import java.util.List; @@ -99,7 +99,7 @@ public class TileEntityShockSuppressor extends TileEntityBase implements IEnergy } @Override - public LazyOptional getEnergyStorage(Direction facing) { + public IEnergyStorage getEnergyStorage(Direction facing) { return this.lazyEnergy; } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityVerticalDigger.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityVerticalDigger.java index 51c228ac2..e58360bdd 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityVerticalDigger.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityVerticalDigger.java @@ -36,12 +36,12 @@ import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.Vec3; -import net.minecraftforge.common.TierSortingRegistry; -import net.minecraftforge.common.util.FakePlayerFactory; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.energy.IEnergyStorage; -import net.minecraftforge.fluids.IFluidBlock; -import net.minecraftforge.registries.ForgeRegistries; +import net.neoforged.neoforge.common.TierSortingRegistry; +import net.neoforged.neoforge.common.util.FakePlayerFactory; +import net.neoforged.neoforge.common.util.LazyOptional; +import net.neoforged.neoforge.energy.IEnergyStorage; +import net.neoforged.neoforge.fluids.IFluidBlock; +import net.neoforged.neoforge.registries.BuiltInRegistries; import javax.annotation.Nullable; import java.util.List; @@ -189,7 +189,7 @@ public class TileEntityVerticalDigger extends TileEntityInventoryBase implements // } // } - String reg = ForgeRegistries.BLOCKS.getKey(block).toString(); + String reg = BuiltInRegistries.BLOCK.getKey(block).toString(); if (!reg.isEmpty()) { for (String string : ConfigStringListValues.MINER_EXTRA_WHITELIST.getValue()) { if (reg.equals(string)) { @@ -210,7 +210,7 @@ public class TileEntityVerticalDigger extends TileEntityInventoryBase implements } private boolean isBlacklisted(Block block) { - String reg = ForgeRegistries.BLOCKS.getKey(block).toString(); + String reg = BuiltInRegistries.BLOCK.getKey(block).toString(); if (!reg.isEmpty()) { for (String string : ConfigStringListValues.MINER_BLACKLIST.getValue()) { if (reg.equals(string)) { @@ -249,7 +249,7 @@ public class TileEntityVerticalDigger extends TileEntityInventoryBase implements } @Override - public LazyOptional getEnergyStorage(Direction facing) { + public IEnergyStorage getEnergyStorage(Direction facing) { return this.lazyEnergy; } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/update/UpdateChecker.java b/src/main/java/de/ellpeck/actuallyadditions/mod/update/UpdateChecker.java index 11887e870..e7e502fd6 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/update/UpdateChecker.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/update/UpdateChecker.java @@ -15,11 +15,11 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.resources.language.I18n; import net.minecraft.network.chat.Component; import net.minecraft.world.entity.player.Player; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.event.TickEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.neoforge.common.NeoForge; +import net.neoforged.neoforge.event.TickEvent; public class UpdateChecker { @@ -52,7 +52,7 @@ public class UpdateChecker { player.displayClientMessage(Component.Serializer.fromJson(I18n.get("info." + ActuallyAdditions.MODID + ".update.buttons", UpdateChecker.CHANGELOG_LINK, UpdateChecker.DOWNLOAD_LINK)), false); } if (threadFinished) { - MinecraftForge.EVENT_BUS.unregister(this); + NeoForge.EVENT_BUS.unregister(this); } } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/util/AssetUtil.java b/src/main/java/de/ellpeck/actuallyadditions/mod/util/AssetUtil.java index a2260c9df..699d81691 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/util/AssetUtil.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/util/AssetUtil.java @@ -42,10 +42,10 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.phys.Vec3; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.client.ForgeHooksClient; -import net.minecraftforge.network.PacketDistributor; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; +import net.neoforged.neoforge.client.ClientHooks; +import net.neoforged.neoforge.network.PacketDistributor; import org.joml.Matrix4f; public final class AssetUtil { @@ -115,7 +115,7 @@ public final class AssetUtil { RenderSystem.enableBlend(); // RenderSystem.pushMatrix(); matrices.pushPose(); - model = ForgeHooksClient.handleCameraTransforms(matrices, model, ItemDisplayContext.FIXED, false); + model = ClientHooks.handleCameraTransforms(matrices, model, ItemDisplayContext.FIXED, false); renderer.render(stack, ItemDisplayContext.FIXED, false, matrices, bufferSource, combinedOverlay, combinedLight, model); // RenderSystem.popMatrix(); @@ -232,7 +232,7 @@ public final class AssetUtil { data.putFloat("Size", size); data.putInt("MaxAge", maxAge); data.putFloat("Alpha", alpha); - PacketHandler.THE_NETWORK.send(PacketDistributor.NEAR.with(() -> new PacketDistributor.TargetPoint(startX, startY, startZ, 96, world.dimension())), new PacketServerToClient(data, PacketHandler.LASER_HANDLER)); + PacketDistributor.NEAR.with(() -> new PacketDistributor.TargetPoint(startX, startY, startZ, 96, world.dimension())).send(new PacketServerToClient(data, PacketHandler.LASER_HANDLER)); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/util/ItemStackHandlerAA.java b/src/main/java/de/ellpeck/actuallyadditions/mod/util/ItemStackHandlerAA.java index 2c194298c..d5068e81c 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/util/ItemStackHandlerAA.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/util/ItemStackHandlerAA.java @@ -12,7 +12,7 @@ package de.ellpeck.actuallyadditions.mod.util; import net.minecraft.core.NonNullList; import net.minecraft.world.item.ItemStack; -import net.minecraftforge.items.ItemStackHandler; +import net.neoforged.neoforge.items.ItemStackHandler; /** * The Actually Additions variant of ItemStackHandler. Provides methods to disallow add/removal based on automation context. Defaults to thinking operations are performed by automation. diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/util/ItemUtil.java b/src/main/java/de/ellpeck/actuallyadditions/mod/util/ItemUtil.java index 79f0bdf3b..05a517d92 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/util/ItemUtil.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/util/ItemUtil.java @@ -10,6 +10,7 @@ package de.ellpeck.actuallyadditions.mod.util; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.player.Player; @@ -17,14 +18,13 @@ import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.enchantment.Enchantment; import net.minecraft.world.item.enchantment.EnchantmentHelper; -import net.minecraftforge.registries.ForgeRegistries; import java.util.Map; public final class ItemUtil { public static Item getItemFromName(String name) { - return ForgeRegistries.ITEMS.getValue(new ResourceLocation(name)); + return BuiltInRegistries.ITEM.get(new ResourceLocation(name)); } // public static boolean contains(ItemStack[] array, ItemStack stack, boolean checkWildcard) { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/util/Lang.java b/src/main/java/de/ellpeck/actuallyadditions/mod/util/Lang.java index ffb261931..3e86b41ab 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/util/Lang.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/util/Lang.java @@ -1,6 +1,6 @@ package de.ellpeck.actuallyadditions.mod.util; -import net.minecraftforge.energy.IEnergyStorage; +import net.neoforged.neoforge.energy.IEnergyStorage; import java.text.NumberFormat; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/util/NetHandlerSpaghettiServer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/util/NetHandlerSpaghettiServer.java deleted file mode 100644 index d7835f40b..000000000 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/util/NetHandlerSpaghettiServer.java +++ /dev/null @@ -1,265 +0,0 @@ -package de.ellpeck.actuallyadditions.mod.util; - -import net.minecraft.network.Connection; -import net.minecraft.network.PacketSendListener; -import net.minecraft.network.chat.Component; -import net.minecraft.network.protocol.Packet; -import net.minecraft.network.protocol.PacketFlow; -import net.minecraft.network.protocol.game.ServerboundAcceptTeleportationPacket; -import net.minecraft.network.protocol.game.ServerboundBlockEntityTagQuery; -import net.minecraft.network.protocol.game.ServerboundChangeDifficultyPacket; -import net.minecraft.network.protocol.game.ServerboundChatPacket; -import net.minecraft.network.protocol.game.ServerboundClientCommandPacket; -import net.minecraft.network.protocol.game.ServerboundClientInformationPacket; -import net.minecraft.network.protocol.game.ServerboundCommandSuggestionPacket; -import net.minecraft.network.protocol.game.ServerboundContainerButtonClickPacket; -import net.minecraft.network.protocol.game.ServerboundContainerClickPacket; -import net.minecraft.network.protocol.game.ServerboundContainerClosePacket; -import net.minecraft.network.protocol.game.ServerboundCustomPayloadPacket; -import net.minecraft.network.protocol.game.ServerboundEditBookPacket; -import net.minecraft.network.protocol.game.ServerboundEntityTagQuery; -import net.minecraft.network.protocol.game.ServerboundInteractPacket; -import net.minecraft.network.protocol.game.ServerboundJigsawGeneratePacket; -import net.minecraft.network.protocol.game.ServerboundKeepAlivePacket; -import net.minecraft.network.protocol.game.ServerboundLockDifficultyPacket; -import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket; -import net.minecraft.network.protocol.game.ServerboundMoveVehiclePacket; -import net.minecraft.network.protocol.game.ServerboundPaddleBoatPacket; -import net.minecraft.network.protocol.game.ServerboundPickItemPacket; -import net.minecraft.network.protocol.game.ServerboundPlaceRecipePacket; -import net.minecraft.network.protocol.game.ServerboundPlayerAbilitiesPacket; -import net.minecraft.network.protocol.game.ServerboundPlayerActionPacket; -import net.minecraft.network.protocol.game.ServerboundPlayerCommandPacket; -import net.minecraft.network.protocol.game.ServerboundPlayerInputPacket; -import net.minecraft.network.protocol.game.ServerboundRecipeBookChangeSettingsPacket; -import net.minecraft.network.protocol.game.ServerboundRecipeBookSeenRecipePacket; -import net.minecraft.network.protocol.game.ServerboundRenameItemPacket; -import net.minecraft.network.protocol.game.ServerboundResourcePackPacket; -import net.minecraft.network.protocol.game.ServerboundSeenAdvancementsPacket; -import net.minecraft.network.protocol.game.ServerboundSelectTradePacket; -import net.minecraft.network.protocol.game.ServerboundSetBeaconPacket; -import net.minecraft.network.protocol.game.ServerboundSetCarriedItemPacket; -import net.minecraft.network.protocol.game.ServerboundSetCommandBlockPacket; -import net.minecraft.network.protocol.game.ServerboundSetCommandMinecartPacket; -import net.minecraft.network.protocol.game.ServerboundSetCreativeModeSlotPacket; -import net.minecraft.network.protocol.game.ServerboundSetJigsawBlockPacket; -import net.minecraft.network.protocol.game.ServerboundSetStructureBlockPacket; -import net.minecraft.network.protocol.game.ServerboundSignUpdatePacket; -import net.minecraft.network.protocol.game.ServerboundSwingPacket; -import net.minecraft.network.protocol.game.ServerboundTeleportToEntityPacket; -import net.minecraft.network.protocol.game.ServerboundUseItemOnPacket; -import net.minecraft.network.protocol.game.ServerboundUseItemPacket; -import net.minecraft.server.network.ServerGamePacketListenerImpl; -import net.minecraft.world.entity.RelativeMovement; -import net.minecraftforge.common.util.FakePlayer; - -import javax.annotation.Nullable; -import java.util.Set; - -public class NetHandlerSpaghettiServer extends ServerGamePacketListenerImpl { - - public NetHandlerSpaghettiServer(FakePlayer player) { - super(null, new Connection(PacketFlow.CLIENTBOUND), player); - } - - @Override - public void disconnect(Component textComponent) { - } - - @Override - public void handlePlayerInput(ServerboundPlayerInputPacket p_147358_1_) { - } - - @Override - public void handleMoveVehicle(ServerboundMoveVehiclePacket p_184338_1_) { - } - - @Override - public void handleAcceptTeleportPacket(ServerboundAcceptTeleportationPacket p_184339_1_) { - } - - @Override - public void handleRecipeBookSeenRecipePacket(ServerboundRecipeBookSeenRecipePacket p_191984_1_) { - } - - @Override - public void handleRecipeBookChangeSettingsPacket(ServerboundRecipeBookChangeSettingsPacket p_241831_1_) { - } - - @Override - public void handleSeenAdvancements(ServerboundSeenAdvancementsPacket p_194027_1_) { - } - - @Override - public void handleCustomCommandSuggestions(ServerboundCommandSuggestionPacket p_195518_1_) { - } - - @Override - public void handleSetCommandBlock(ServerboundSetCommandBlockPacket p_210153_1_) { - } - - @Override - public void handleSetCommandMinecart(ServerboundSetCommandMinecartPacket p_210158_1_) { - } - - @Override - public void handlePickItem(ServerboundPickItemPacket p_210152_1_) { - } - - @Override - public void handleRenameItem(ServerboundRenameItemPacket p_210155_1_) { - } - - @Override - public void handleSetBeaconPacket(ServerboundSetBeaconPacket p_210154_1_) { - } - - @Override - public void handleSetStructureBlock(ServerboundSetStructureBlockPacket p_210157_1_) { - } - - @Override - public void handleSetJigsawBlock(ServerboundSetJigsawBlockPacket p_217262_1_) { - } - - @Override - public void handleJigsawGenerate(ServerboundJigsawGeneratePacket p_230549_1_) { - } - - @Override - public void handleSelectTrade(ServerboundSelectTradePacket p_210159_1_) { - } - - @Override - public void handleEditBook(ServerboundEditBookPacket p_210156_1_) { - } - - @Override - public void handleEntityTagQuery(ServerboundEntityTagQuery p_211526_1_) { - } - - @Override - public void handleBlockEntityTagQuery(ServerboundBlockEntityTagQuery p_211525_1_) { - } - - @Override - public void handleMovePlayer(ServerboundMovePlayerPacket p_147347_1_) { - } - - @Override - public void teleport(double p_147364_1_, double p_147364_3_, double p_147364_5_, float p_147364_7_, float p_147364_8_) { - } - - @Override - public void teleport(double pX, double pY, double pZ, float pYaw, float pPitch, Set pRelativeSet) { - - } - - @Override - public void handlePlayerAction(ServerboundPlayerActionPacket p_147345_1_) { - } - - @Override - public void handleUseItemOn(ServerboundUseItemOnPacket p_184337_1_) { - } - - @Override - public void handleUseItem(ServerboundUseItemPacket p_147346_1_) { - } - - @Override - public void handleTeleportToEntityPacket(ServerboundTeleportToEntityPacket p_175088_1_) { - } - - @Override - public void handleResourcePackResponse(ServerboundResourcePackPacket p_175086_1_) { - } - - @Override - public void handlePaddleBoat(ServerboundPaddleBoatPacket p_184340_1_) { - } - - @Override - public void onDisconnect(Component p_147231_1_) { - } - - @Override - public void send(Packet p_147359_1_) { - } - - @Override - public void send(Packet pPacket, @Nullable PacketSendListener pListener) { - } - - @Override - public void handleSetCarriedItem(ServerboundSetCarriedItemPacket p_147355_1_) { - } - - @Override - public void handleChat(ServerboundChatPacket p_147354_1_) { - } - - @Override - public void handleAnimate(ServerboundSwingPacket p_175087_1_) { - } - - @Override - public void handlePlayerCommand(ServerboundPlayerCommandPacket p_147357_1_) { - } - - @Override - public void handleInteract(ServerboundInteractPacket p_147340_1_) { - } - - @Override - public void handleClientCommand(ServerboundClientCommandPacket p_147342_1_) { - } - - @Override - public void handleContainerClose(ServerboundContainerClosePacket p_147356_1_) { - } - - @Override - public void handleContainerClick(ServerboundContainerClickPacket p_147351_1_) { - } - - @Override - public void handlePlaceRecipe(ServerboundPlaceRecipePacket p_194308_1_) { - } - - @Override - public void handleContainerButtonClick(ServerboundContainerButtonClickPacket p_147338_1_) { - } - - @Override - public void handleSetCreativeModeSlot(ServerboundSetCreativeModeSlotPacket p_147344_1_) { - } - - @Override - public void handleSignUpdate(ServerboundSignUpdatePacket p_147343_1_) { - } - - @Override - public void handleKeepAlive(ServerboundKeepAlivePacket p_147353_1_) { - } - - @Override - public void handlePlayerAbilities(ServerboundPlayerAbilitiesPacket p_147348_1_) { - } - - @Override - public void handleClientInformation(ServerboundClientInformationPacket p_147352_1_) { - } - - @Override - public void handleCustomPayload(ServerboundCustomPayloadPacket p_147349_1_) { - } - - @Override - public void handleChangeDifficulty(ServerboundChangeDifficultyPacket p_217263_1_) { - } - - @Override - public void handleLockDifficulty(ServerboundLockDifficultyPacket p_217261_1_) { - } -} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/util/RefHelp.java b/src/main/java/de/ellpeck/actuallyadditions/mod/util/RefHelp.java index 2240279df..97838cdf9 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/util/RefHelp.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/util/RefHelp.java @@ -2,7 +2,7 @@ package de.ellpeck.actuallyadditions.mod.util; import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; -import net.minecraftforge.fml.loading.FMLLoader; +import net.neoforged.fml.loading.FMLLoader; import org.apache.commons.lang3.StringUtils; import javax.annotation.Nonnull; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/util/StackUtil.java b/src/main/java/de/ellpeck/actuallyadditions/mod/util/StackUtil.java index e51efc290..70234b278 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/util/StackUtil.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/util/StackUtil.java @@ -14,7 +14,7 @@ import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.util.compat.SlotlessableItemHandlerWrapper; import net.minecraft.core.NonNullList; import net.minecraft.world.item.ItemStack; -import net.minecraftforge.items.IItemHandler; +import net.neoforged.neoforge.items.IItemHandler; import java.util.Collection; import java.util.List; @@ -214,14 +214,17 @@ public final class StackUtil { // } } - return wrapper.getNormalHandler().map(e -> { + IItemHandler normalHandler = wrapper.getNormalHandler(); + if (normalHandler != null) { ItemStack remain = stack.copy(); - for (int i = Math.max(0, slotStart); i < Math.min(slotEnd, e.getSlots()); i++) { - remain = e.insertItem(i, remain, simulate); + for (int i = Math.max(0, slotStart); i < Math.min(slotEnd, normalHandler.getSlots()); i++) { + remain = normalHandler.insertItem(i, remain, simulate); } return remain; - }).orElse(stack); + } else { + return stack; + } } /** diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/util/StringUtil.java b/src/main/java/de/ellpeck/actuallyadditions/mod/util/StringUtil.java index 6c04c0d90..ced2ec537 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/util/StringUtil.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/util/StringUtil.java @@ -14,8 +14,8 @@ import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.gui.Font; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.resources.language.I18n; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; @Deprecated public final class StringUtil { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/util/Util.java b/src/main/java/de/ellpeck/actuallyadditions/mod/util/Util.java index dabdd4792..22b4e774c 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/util/Util.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/util/Util.java @@ -11,7 +11,7 @@ package de.ellpeck.actuallyadditions.mod.util; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; -import net.minecraftforge.fml.loading.FMLLoader; +import net.neoforged.fml.loading.FMLLoader; public final class Util { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/util/WorldUtil.java b/src/main/java/de/ellpeck/actuallyadditions/mod/util/WorldUtil.java index edda47bcd..8d9eafd85 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/util/WorldUtil.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/util/WorldUtil.java @@ -33,16 +33,15 @@ import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.HitResult; import net.minecraft.world.phys.Vec3; -import net.minecraftforge.common.ForgeHooks; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.common.capabilities.ForgeCapabilities; -import net.minecraftforge.common.util.FakePlayer; -import net.minecraftforge.common.util.FakePlayerFactory; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.energy.IEnergyStorage; -import net.minecraftforge.event.level.BlockEvent.BreakEvent; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.capability.IFluidHandler; +import net.neoforged.neoforge.capabilities.Capabilities; +import net.neoforged.neoforge.common.CommonHooks; +import net.neoforged.neoforge.common.NeoForge; +import net.neoforged.neoforge.common.util.FakePlayer; +import net.neoforged.neoforge.common.util.FakePlayerFactory; +import net.neoforged.neoforge.energy.IEnergyStorage; +import net.neoforged.neoforge.event.level.BlockEvent.BreakEvent; +import net.neoforged.neoforge.fluids.FluidStack; +import net.neoforged.neoforge.fluids.capability.IFluidHandler; import java.util.ArrayList; import java.util.List; @@ -113,38 +112,34 @@ public final class WorldUtil { return extracted; } - public static void doEnergyInteraction(BlockEntity tileFrom, BlockEntity tileTo, Direction sideTo, int maxTransfer) { + public static void doEnergyInteraction(Level level, BlockPos posFrom, BlockPos posTo, Direction sideTo, int maxTransfer) { if (maxTransfer > 0) { Direction opp = sideTo == null ? null : sideTo.getOpposite(); - LazyOptional handlerFrom = tileFrom.getCapability(ForgeCapabilities.ENERGY, sideTo); - LazyOptional handlerTo = tileTo.getCapability(ForgeCapabilities.ENERGY, opp); - handlerFrom.ifPresent((from) -> { - handlerTo.ifPresent((to) -> { - int drain = from.extractEnergy(maxTransfer, true); - if (drain > 0) { - int filled = to.receiveEnergy(drain, false); - from.extractEnergy(filled, false); - } - }); - }); + IEnergyStorage handlerFrom = level.getCapability(Capabilities.EnergyStorage.BLOCK, posFrom, sideTo); + IEnergyStorage handlerTo = level.getCapability(Capabilities.EnergyStorage.BLOCK, posTo, opp); + if (handlerFrom != null && handlerTo != null) { + int drain = handlerFrom.extractEnergy(maxTransfer, true); + if (drain > 0) { + int filled = handlerTo.receiveEnergy(drain, false); + handlerFrom.extractEnergy(filled, false); + } + } } } - public static void doFluidInteraction(BlockEntity tileFrom, BlockEntity tileTo, Direction sideTo, int maxTransfer) { + public static void doFluidInteraction(Level level, BlockPos posFrom, BlockPos posTo, Direction sideTo, int maxTransfer) { if (maxTransfer > 0) { - LazyOptional optionalFrom = tileFrom.getCapability(ForgeCapabilities.FLUID_HANDLER, sideTo); - LazyOptional optionalTo = tileTo.getCapability(ForgeCapabilities.FLUID_HANDLER, sideTo.getOpposite()); - optionalFrom.ifPresent((from) -> { - optionalTo.ifPresent((to) -> { - FluidStack drain = from.drain(maxTransfer, IFluidHandler.FluidAction.SIMULATE); - if (!drain.isEmpty()) { - int filled = to.fill(drain.copy(), IFluidHandler.FluidAction.EXECUTE); - from.drain(filled, IFluidHandler.FluidAction.EXECUTE); - } - }); - }); + IFluidHandler handlerFrom = level.getCapability(Capabilities.FluidHandler.BLOCK, posFrom, sideTo); + IFluidHandler handlerTo = level.getCapability(Capabilities.FluidHandler.BLOCK, posTo, sideTo.getOpposite()); + if (handlerFrom != null && handlerTo != null) { + FluidStack drain = handlerFrom.drain(maxTransfer, IFluidHandler.FluidAction.SIMULATE); + if (!drain.isEmpty()) { + int filled = handlerTo.fill(drain.copy(), IFluidHandler.FluidAction.EXECUTE); + handlerFrom.drain(filled, IFluidHandler.FluidAction.EXECUTE); + } + } } } @@ -298,7 +293,7 @@ public final class WorldUtil { BlockState state = level.getBlockState(pos); BreakEvent event = new BreakEvent(level, pos, state, fake); - if (!MinecraftForge.EVENT_BUS.post(event)) { + if (!NeoForge.EVENT_BUS.post(event).isCanceled()) { //return ForgeEventFactory.fireBlockHarvesting(drops, world, pos, state, 0, 1, false, fake); //TODO what?! } } @@ -336,7 +331,7 @@ public final class WorldUtil { // server sided handling if (!level.isClientSide) { // send the blockbreak event - int xp = ForgeHooks.onBlockBreakEvent(level, ((ServerPlayer) player).gameMode.getGameModeForPlayer(), (ServerPlayer) player, pos); + int xp = CommonHooks.onBlockBreakEvent(level, ((ServerPlayer) player).gameMode.getGameModeForPlayer(), (ServerPlayer) player, pos); if (xp == -1) { return false; } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/util/compat/SlotlessableItemHandlerWrapper.java b/src/main/java/de/ellpeck/actuallyadditions/mod/util/compat/SlotlessableItemHandlerWrapper.java index f9a54e3bd..45fd25917 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/util/compat/SlotlessableItemHandlerWrapper.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/util/compat/SlotlessableItemHandlerWrapper.java @@ -10,20 +10,20 @@ package de.ellpeck.actuallyadditions.mod.util.compat; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.items.IItemHandler; +import net.neoforged.neoforge.items.IItemHandler; public class SlotlessableItemHandlerWrapper { + //TODO: Check if we need this wrapper at all? The previous implementation used CommonCapabilities ISlotlessItemhandler - private final LazyOptional normalHandler; + private final IItemHandler normalHandler; private final Object slotlessHandler; - public SlotlessableItemHandlerWrapper(LazyOptional normalHandler, Object slotlessHandler) { + public SlotlessableItemHandlerWrapper(IItemHandler normalHandler, Object slotlessHandler) { this.normalHandler = normalHandler; this.slotlessHandler = slotlessHandler; } - public LazyOptional getNormalHandler() { + public IItemHandler getNormalHandler() { return this.normalHandler; } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/util/crafting/RecipeHandler.java b/src/main/java/de/ellpeck/actuallyadditions/mod/util/crafting/RecipeHandler.java index c12bcf744..547d80bd0 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/util/crafting/RecipeHandler.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/util/crafting/RecipeHandler.java @@ -17,20 +17,20 @@ // // public static IRecipe lastRecipe; // -// public static void addOreDictRecipe(ItemStack output, Object... inputs) { -// addShapedRecipe(output, inputs); +// public static void addOreDictRecipe(ItemStack stack, Object... inputs) { +// addShapedRecipe(stack, inputs); // } // -// public static void addShapelessOreDictRecipe(ItemStack output, Object... inputs) { -// addShapelessRecipe(output, inputs); +// public static void addShapelessOreDictRecipe(ItemStack stack, Object... inputs) { +// addShapelessRecipe(stack, inputs); // } // -// public static void addShapelessRecipe(ItemStack output, Object... inputs) { -// RecipeHelper.addOldShapeless(output, inputs); +// public static void addShapelessRecipe(ItemStack stack, Object... inputs) { +// RecipeHelper.addOldShapeless(stack, inputs); // } // -// public static void addShapedRecipe(ItemStack output, Object... inputs) { -// RecipeHelper.addOldShaped(output, inputs); +// public static void addShapedRecipe(ItemStack stack, Object... inputs) { +// RecipeHelper.addOldShaped(stack, inputs); // } // //} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/util/crafting/RecipeHelper.java b/src/main/java/de/ellpeck/actuallyadditions/mod/util/crafting/RecipeHelper.java index 4e1cf3317..8ef6fe584 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/util/crafting/RecipeHelper.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/util/crafting/RecipeHelper.java @@ -51,108 +51,108 @@ // /* // * This adds a shaped recipe to the list of crafting recipes, using the forge format. // */ -// public static void addOldShaped(ItemStack output, Object... input) { +// public static void addOldShaped(ItemStack stack, Object... input) { // ShapedPrimer primer = CraftingHelper.parseShaped(input); -// addRecipe(j++, new ShapedRecipes(new ResourceLocation(MODID, "recipes" + j).toString(), primer.width, primer.height, primer.input, output)); +// addRecipe(j++, new ShapedRecipes(new ResourceLocation(MODID, "recipes" + j).toString(), primer.width, primer.height, primer.input, stack)); // } // // /* // * This adds a shaped recipe to the list of crafting recipes, using the forge format, with a custom group. // */ -// public static void addOldShaped(String group, ItemStack output, Object... input) { +// public static void addOldShaped(String group, ItemStack stack, Object... input) { // ShapedPrimer primer = CraftingHelper.parseShaped(input); -// addRecipe(j++, new ShapedRecipes(new ResourceLocation(MODID, group).toString(), primer.width, primer.height, primer.input, output)); +// addRecipe(j++, new ShapedRecipes(new ResourceLocation(MODID, group).toString(), primer.width, primer.height, primer.input, stack)); // } // // /* // * This adds a shaped recipe to the list of crafting recipes, using the forge format, with a custom group. // */ -// public static void addOldShaped(String name, String group, ItemStack output, Object... input) { +// public static void addOldShaped(String name, String group, ItemStack stack, Object... input) { // ShapedPrimer primer = CraftingHelper.parseShaped(input); -// addRecipe(j++, new ShapedRecipes(new ResourceLocation(MODID, group).toString(), primer.width, primer.height, primer.input, output).setRegistryName(MODID, name)); +// addRecipe(j++, new ShapedRecipes(new ResourceLocation(MODID, group).toString(), primer.width, primer.height, primer.input, stack).setRegistryName(MODID, name)); // } // // /* // * This adds a shapeless recipe to the list of crafting recipes, using the forge format. // */ -// public static void addOldShapeless(ItemStack output, Object... input) { -// addRecipe(j++, new ShapelessRecipes(new ResourceLocation(MODID, "recipes" + j).toString(), output, createInput(input))); +// public static void addOldShapeless(ItemStack stack, Object... input) { +// addRecipe(j++, new ShapelessRecipes(new ResourceLocation(MODID, "recipes" + j).toString(), stack, createInput(input))); // } // // /* // * This adds a shapeless recipe to the list of crafting recipes, using the forge format, with a custom group. // */ -// public static void addOldShapeless(String group, ItemStack output, Object... input) { -// addRecipe(j++, new ShapelessRecipes(new ResourceLocation(MODID, group).toString(), output, createInput(input))); +// public static void addOldShapeless(String group, ItemStack stack, Object... input) { +// addRecipe(j++, new ShapelessRecipes(new ResourceLocation(MODID, group).toString(), stack, createInput(input))); // } // -// public static void addOldShapeless(String name, String group, ItemStack output, Object... input) { -// addRecipe(j++, new ShapelessRecipes(new ResourceLocation(MODID, group).toString(), output, createInput(input)).setRegistryName(MODID, name)); +// public static void addOldShapeless(String name, String group, ItemStack stack, Object... input) { +// addRecipe(j++, new ShapelessRecipes(new ResourceLocation(MODID, group).toString(), stack, createInput(input)).setRegistryName(MODID, name)); // } // // /* -// * Adds a shapeless recipe with X output using an array of inputs. Use Strings for OreDictionary support. This array is not ordered. +// * Adds a shapeless recipe with X stack using an array of inputs. Use Strings for OreDictionary support. This array is not ordered. // */ -// public static void addShapeless(ItemStack output, Object... inputs) { -// addRecipe(j++, new ShapelessRecipes(MODID + ":" + j, output, createInput(inputs))); +// public static void addShapeless(ItemStack stack, Object... inputs) { +// addRecipe(j++, new ShapelessRecipes(MODID + ":" + j, stack, createInput(inputs))); // } // -// public static void addShapeless(Item output, Object... inputs) { -// addShapeless(new ItemStack(output), inputs); +// public static void addShapeless(Item stack, Object... inputs) { +// addShapeless(new ItemStack(stack), inputs); // } // -// public static void addShapeless(Block output, Object... inputs) { -// addShapeless(new ItemStack(output), inputs); +// public static void addShapeless(Block stack, Object... inputs) { +// addShapeless(new ItemStack(stack), inputs); // } // // /* -// * Adds a shapeless recipe with X output using an array of inputs. Use Strings for OreDictionary support. This array is not ordered. This has a custom group. +// * Adds a shapeless recipe with X stack using an array of inputs. Use Strings for OreDictionary support. This array is not ordered. This has a custom group. // */ -// public static void addShapeless(String group, ItemStack output, Object... inputs) { -// addRecipe(j++, new ShapelessRecipes(MODID + ":" + group, output, createInput(inputs))); +// public static void addShapeless(String group, ItemStack stack, Object... inputs) { +// addRecipe(j++, new ShapelessRecipes(MODID + ":" + group, stack, createInput(inputs))); // } // -// public static void addShapeless(String group, Item output, Object... inputs) { -// addShapeless(group, new ItemStack(output), inputs); +// public static void addShapeless(String group, Item stack, Object... inputs) { +// addShapeless(group, new ItemStack(stack), inputs); // } // -// public static void addShapeless(String group, Block output, Object... inputs) { -// addShapeless(group, new ItemStack(output), inputs); +// public static void addShapeless(String group, Block stack, Object... inputs) { +// addShapeless(group, new ItemStack(stack), inputs); // } // // /* -// * Adds a shapeless recipe with X output on a crafting grid that is W x H, using an array of inputs. Use null for nothing, use Strings for OreDictionary support, this array must have a length of width * height. +// * Adds a shapeless recipe with X stack on a crafting grid that is W x H, using an array of inputs. Use null for nothing, use Strings for OreDictionary support, this array must have a length of width * height. // * This array is ordered, and items must follow from left to right, top to bottom of the crafting grid. // */ -// public static void addShaped(ItemStack output, int width, int height, Object... input) { -// addRecipe(j++, genShaped(output, width, height, input)); +// public static void addShaped(ItemStack stack, int width, int height, Object... input) { +// addRecipe(j++, genShaped(stack, width, height, input)); // } // -// public static void addShaped(Item output, int width, int height, Object... input) { -// addShaped(new ItemStack(output), width, height, input); +// public static void addShaped(Item stack, int width, int height, Object... input) { +// addShaped(new ItemStack(stack), width, height, input); // } // -// public static void addShaped(Block output, int width, int height, Object... input) { -// addShaped(new ItemStack(output), width, height, input); +// public static void addShaped(Block stack, int width, int height, Object... input) { +// addShaped(new ItemStack(stack), width, height, input); // } // // /* -// * Adds a shapeless recipe with X output on a crafting grid that is W x H, using an array of inputs. Use null for nothing, use Strings for OreDictionary support, this array must have a length of width * height. +// * Adds a shapeless recipe with X stack on a crafting grid that is W x H, using an array of inputs. Use null for nothing, use Strings for OreDictionary support, this array must have a length of width * height. // * This array is ordered, and items must follow from left to right, top to bottom of the crafting grid. This has a custom group. // */ -// public static void addShaped(String group, ItemStack output, int width, int height, Object... input) { -// addRecipe(j++, genShaped(MODID + ":" + group, output, width, height, input)); +// public static void addShaped(String group, ItemStack stack, int width, int height, Object... input) { +// addRecipe(j++, genShaped(MODID + ":" + group, stack, width, height, input)); // } // -// public static void addShaped(String group, Item output, int width, int height, Object... input) { -// addShaped(group, new ItemStack(output), width, height, input); +// public static void addShaped(String group, Item stack, int width, int height, Object... input) { +// addShaped(group, new ItemStack(stack), width, height, input); // } // -// public static void addShaped(String group, Block output, int width, int height, Object... input) { -// addShaped(group, new ItemStack(output), width, height, input); +// public static void addShaped(String group, Block stack, int width, int height, Object... input) { +// addShaped(group, new ItemStack(stack), width, height, input); // } // -// public static ShapedRecipes genShaped(ItemStack output, int l, int w, Object[] input) { +// public static ShapedRecipes genShaped(ItemStack stack, int l, int w, Object[] input) { // if (input[0] instanceof Object[]) { // input = (Object[]) input[0]; // } @@ -173,10 +173,10 @@ // } // } // -// return new ShapedRecipes(MODID + ":" + j, l, w, inputL, output); +// return new ShapedRecipes(MODID + ":" + j, l, w, inputL, stack); // } // -// public static ShapedRecipes genShaped(String group, ItemStack output, int l, int w, Object[] input) { +// public static ShapedRecipes genShaped(String group, ItemStack stack, int l, int w, Object[] input) { // if (input[0] instanceof List) { // input = ((List) input[0]).toArray(); // } else if (input[0] instanceof Object[]) { @@ -201,7 +201,7 @@ // } // } // -// return new ShapedRecipes(group, l, w, inputL, output); +// return new ShapedRecipes(group, l, w, inputL, stack); // } // // public static NonNullList createInput(Object[] input) { diff --git a/src/main/java/de/ellpeck/actuallyadditions/registration/AABlockReg.java b/src/main/java/de/ellpeck/actuallyadditions/registration/AABlockReg.java index a5529448d..9dddacd8a 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/registration/AABlockReg.java +++ b/src/main/java/de/ellpeck/actuallyadditions/registration/AABlockReg.java @@ -7,7 +7,8 @@ import net.minecraft.world.item.Item; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraftforge.registries.RegistryObject; +import net.neoforged.neoforge.registries.DeferredBlock; +import net.neoforged.neoforge.registries.DeferredItem; import javax.annotation.Nonnull; import java.util.Objects; @@ -16,9 +17,9 @@ import java.util.function.Supplier; public class AABlockReg implements Supplier { private final String name; - private RegistryObject block; - private RegistryObject item; - private RegistryObject> tileEntityType; + private DeferredBlock block; + private DeferredItem item; + private Supplier> tileEntityType; public AABlockReg(String name, Supplier blockSupplier, Function itemSupplier, BlockEntityType.BlockEntitySupplier tileSupplier) { this.name = name; diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg index 456baad49..86d2587cd 100644 --- a/src/main/resources/META-INF/accesstransformer.cfg +++ b/src/main/resources/META-INF/accesstransformer.cfg @@ -1,3 +1,3 @@ public net.minecraft.world.damagesource.DamageSources *() # DamageSources -public net.minecraft.world.damagesource.DamageSources f_268645_ # damageTypes -public-f net.minecraft.data.recipes.RecipeProvider m_6055_()Ljava/lang/String; # getName \ No newline at end of file +public net.minecraft.world.damagesource.DamageSources damageTypes +public-f net.minecraft.data.recipes.RecipeProvider getName()Ljava/lang/String; \ No newline at end of file diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 694c2f555..30d6e455f 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -1,6 +1,6 @@ modLoader="javafml" -loaderVersion="[47,)" +loaderVersion="[2,)" license="MIT" [[mods]] modId="actuallyadditions" @@ -14,15 +14,15 @@ Do you want Automation? Wireless Transport? Better Machines? A cup o' Coffee? Ch ''' [[dependencies.actuallyadditions]] - modId="forge" - mandatory=true - versionRange="[47,)" + modId="neoforge" + type="required" + versionRange="[20.4.167,)" ordering="NONE" side="BOTH" [[dependencies.actuallyadditions]] modId="minecraft" - mandatory=true - versionRange="[1.20.1,1.21)" + type="required" + versionRange="[1.20.4,1.21)" ordering="NONE" side="BOTH" diff --git a/src/main/resources/pack.mcmeta b/src/main/resources/pack.mcmeta index e087718a9..4370def5e 100644 --- a/src/main/resources/pack.mcmeta +++ b/src/main/resources/pack.mcmeta @@ -1,7 +1,8 @@ { "pack": { - "description": "actuallyadditions resources", - "pack_format": 6, - "_comment": "A pack_format of 6 requires json lang files and some texture changes from 1.16.2. Note: we require v6 pack meta for all mods." + "description": { + "text": "actuallyadditions resources" + }, + "pack_format": 22 } }