diff --git a/build.gradle b/build.gradle index 136fd9e..69a346e 100644 --- a/build.gradle +++ b/build.gradle @@ -1,13 +1,10 @@ plugins { id 'eclipse' id 'maven-publish' - id 'net.neoforged.gradle' version '[6.0.13, 6.2)' - id 'org.spongepowered.mixin' version '[0.7,0.8)' - id 'org.parchmentmc.librarian.forgegradle' version '[1,2)' - id 'org.moddingx.modgradle.mapping' version '[4,5)' - id 'org.moddingx.modgradle.sourcejar' version '[4,5)' apply false + id 'net.neoforged.gradle.userdev' version '7.0.+' id 'io.github.0ffz.github-packages' version '[1,2)' - id 'io.github.p03w.machete' version '2.0.1' + id 'com.matthewprenger.cursegradle' version '[1.4,1.5)' + id 'com.modrinth.minotaur' version '[2,3)' } version = "${mc_version}-${mod_version}-neoforge" @@ -19,49 +16,30 @@ base { java.toolchain.languageVersion = JavaLanguageVersion.of(17) -apply plugin: 'org.moddingx.modgradle.sourcejar' +runs { + configureEach { + workingDirectory project.file('run') + systemProperty "${mod_id}.iside", 'true' + systemProperty 'forge.logging.console.level', 'info' -minecraft { - mappings channel: 'sugarcane', version: project.mappings - - copyIdeResources = true - - accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') - - runs { - configureEach { - workingDirectory project.file('run') - - property "${mod_id}.iside", 'true' - - property 'forge.logging.console.level', 'info' - - mods { - "${mod_id}" { - source sourceSets.main - } - } - } - - client { - property 'forge.enabledGameTestNamespaces', mod_id - } - - server { - property 'forge.enabledGameTestNamespaces', mod_id + modSource project.sourceSets.main + } - args '--nogui' - } + client { + systemProperty 'forge.enabledGameTestNamespaces', mod_id + } - gameTestServer { - property 'forge.enabledGameTestNamespaces', mod_id - } + server { + systemProperty 'forge.enabledGameTestNamespaces', mod_id + programArgument '--nogui' + } - data { - args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/'), '--existing', file('src/generated/resources/') + gameTestServer { + systemProperty 'neoforge.enabledGameTestNamespaces', mod_id + } - environment 'target', 'fmluserdevdata' - } + data { + programArguments.addAll '--mod', mod_id, '--all', '--output', file('src/generated/resources/').getAbsolutePath(), '--existing', file('src/main/resources/').getAbsolutePath(), '--existing', file('src/generated/resources/').getAbsolutePath() } } @@ -69,33 +47,24 @@ sourceSets.main.resources { srcDir 'src/generated/resources' } -processResources { - exclude '.cache/' -} - -machete { - jij.enabled = false - json.enabled = true - png.enabled = false - sourceFileStriping.enabled = false - lvtStriping.enabled = false +subsystems { + parchment { + minecraftVersion = project.mc_version + mappingsVersion = project.mappings + } } -tasks.jar.finalizedBy('optimizeOutputsOfJar') - dependencies { - minecraft "net.neoforged:forge:${project.mc_version}-${project.neoforge_version}" + implementation "net.neoforged:neoforge:${project.neoforge_version}" - annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' +// compileOnly "mezz.jei:jei-${project.mc_version}-common:${project.jei_version}" +// compileOnly "mezz.jei:jei-${project.mc_version}-forge:${project.jei_version}" - compileOnly "mezz.jei:jei-${project.mc_version}-common:${project.jei_version}" - compileOnly "mezz.jei:jei-${project.mc_version}-forge:${project.jei_version}" + compileOnly "me.shedaniel:RoughlyEnoughItems-api-forge:$rei_version" + compileOnly "me.shedaniel:RoughlyEnoughItems-default-plugin-forge:$rei_version" - compileOnly fg.deobf("me.shedaniel:RoughlyEnoughItems-api-forge:$rei_version") - compileOnly fg.deobf("me.shedaniel:RoughlyEnoughItems-default-plugin-forge:$rei_version") - - compileOnly fg.deobf("me.shedaniel.cloth:cloth-config-forge:$cloth_config_version") - compileOnly fg.deobf("dev.architectury:architectury-forge:$architectury_version") + compileOnly "me.shedaniel.cloth:cloth-config-forge:$cloth_config_version" + compileOnly "dev.architectury:architectury-forge:$architectury_version" } repositories { @@ -104,6 +73,20 @@ repositories { maven { url = "https://maven.architectury.dev/" } } +//processResources { +// exclude '.cache/' +//} +// +//machete { +// jij.enabled = false +// json.enabled = true +// png.enabled = false +// sourceFileStriping.enabled = false +// lvtStriping.enabled = false +//} +// +//tasks.jar.finalizedBy('optimizeOutputsOfJar') + tasks.named('jar', Jar).configure { manifest { attributes([ @@ -116,24 +99,24 @@ tasks.named('jar', Jar).configure { "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ") ]) } - - finalizedBy 'reobfJar' -} - -tasks.named(sourceSets.main.compileJavaTaskName) { - outputs.file("${it.temporaryDir}/${it.name}-refmap.json").withPropertyName("mixin refmap") } compileJava { options.incremental = false } +tasks.register('sourceJar', Jar) { + dependsOn 'classes' + from sourceSets.main.allSource + archiveClassifier = 'sources' +} + publishing { publications { mavenJava(MavenPublication) { artifactId project.archivesBaseName - artifact jar - artifact sourceJar + artifact project.jar + artifact project.sourceJar } } repositories { @@ -147,8 +130,3 @@ publishing { } } } - -mixin { - config "${project.mod_id}.mixins.json" - add sourceSets.main, "${project.mod_id}.refmap.json" -} diff --git a/gradle.properties b/gradle.properties index 3cca5b6..133afe5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,12 +7,12 @@ org.gradle.daemon=false mod_id=nitrogen_internals mod_name=Nitrogen mod_version=1.0.2 -mc_version=1.20.1 -neoforge_version=47.1.70 -mappings=2023.08.20-1.20.1 +mc_version=1.20.2 +neoforge_version=20.2.88 +mappings=2023.12.10 # Dependencies -jei_version=15.2.0.27 -rei_version=12.0.684 -cloth_config_version=11.1.118 -architectury_version=9.1.12 +#jei_version=15.2.0.27 +rei_version=13.0.685 +cloth_config_version=12.0.119 +architectury_version=10.0.17 diff --git a/settings.gradle b/settings.gradle index bf02080..7d8be9f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,23 +1,8 @@ pluginManagement { - resolutionStrategy { - eachPlugin { - var plugin = requested.id.toString() - - // ModGradle - if (plugin.startsWith('org.moddingx.modgradle.')) { - useModule "org.moddingx:ModGradle:${requested.version}" - } - } - } repositories { gradlePluginPortal() maven { url = 'https://maven.neoforged.net/releases/' } maven { url = 'https://repo.spongepowered.org/maven' } maven { url = 'https://maven.parchmentmc.org' } - maven { url = 'https://maven.moddingx.org' } } } - -plugins { - id 'org.gradle.toolchains.foojay-resolver-convention' version '0.5.0' -} diff --git a/src/main/java/com/aetherteam/nitrogen/Nitrogen.java b/src/main/java/com/aetherteam/nitrogen/Nitrogen.java index 91a29e8..413b084 100644 --- a/src/main/java/com/aetherteam/nitrogen/Nitrogen.java +++ b/src/main/java/com/aetherteam/nitrogen/Nitrogen.java @@ -17,14 +17,14 @@ import net.minecraft.server.packs.PackType; import net.minecraft.server.packs.metadata.pack.PackMetadataSection; import net.minecraft.world.entity.player.Player; -import net.minecraftforge.data.event.GatherDataEvent; -import net.minecraftforge.event.entity.player.PlayerEvent; -import net.minecraftforge.event.server.ServerStartingEvent; -import net.minecraftforge.eventbus.api.IEventBus; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; -import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.bus.api.IEventBus; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent; +import net.neoforged.neoforge.data.event.GatherDataEvent; +import net.neoforged.neoforge.event.entity.player.PlayerEvent; +import net.neoforged.neoforge.event.server.ServerStartingEvent; +import net.neoforged.fml.common.Mod; import org.slf4j.Logger; import java.time.LocalDateTime; @@ -39,10 +39,9 @@ public class Nitrogen { public static final String MODID = "nitrogen_internals"; public static final Logger LOGGER = LogUtils.getLogger(); - public Nitrogen() { - IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); - modEventBus.addListener(this::commonSetup); - modEventBus.addListener(this::dataSetup); + public Nitrogen(IEventBus bus, Dist dist) { + bus.addListener(this::commonSetup); + bus.addListener(this::dataSetup); } public void commonSetup(FMLCommonSetupEvent event) { diff --git a/src/main/java/com/aetherteam/nitrogen/api/users/UserSavedData.java b/src/main/java/com/aetherteam/nitrogen/api/users/UserSavedData.java index aa5bc61..e9129c4 100644 --- a/src/main/java/com/aetherteam/nitrogen/api/users/UserSavedData.java +++ b/src/main/java/com/aetherteam/nitrogen/api/users/UserSavedData.java @@ -88,7 +88,7 @@ public static UserSavedData create() { * @return The {@link UserSavedData} corresponding to the data file. */ public static UserSavedData compute(DimensionDataStorage dataStorage) { - return dataStorage.computeIfAbsent(UserSavedData::load, UserSavedData::create, FILE_NAME); + return dataStorage.computeIfAbsent(new SavedData.Factory<>(UserSavedData::create, UserSavedData::load, null), FILE_NAME); } /** diff --git a/src/main/java/com/aetherteam/nitrogen/capability/CapabilityProvider.java b/src/main/java/com/aetherteam/nitrogen/capability/CapabilityProvider.java index ca95ff0..4fbfebf 100644 --- a/src/main/java/com/aetherteam/nitrogen/capability/CapabilityProvider.java +++ b/src/main/java/com/aetherteam/nitrogen/capability/CapabilityProvider.java @@ -2,10 +2,10 @@ import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.common.capabilities.ICapabilitySerializable; -import net.minecraftforge.common.util.INBTSerializable; -import net.minecraftforge.common.util.LazyOptional; +import net.neoforged.neoforge.common.capabilities.Capability; +import net.neoforged.neoforge.common.capabilities.ICapabilitySerializable; +import net.neoforged.neoforge.common.util.INBTSerializable; +import net.neoforged.neoforge.common.util.LazyOptional; /** * Record used for creating basic capability providers. diff --git a/src/main/java/com/aetherteam/nitrogen/capability/INBTSynchable.java b/src/main/java/com/aetherteam/nitrogen/capability/INBTSynchable.java index 8de92f1..7f856e8 100644 --- a/src/main/java/com/aetherteam/nitrogen/capability/INBTSynchable.java +++ b/src/main/java/com/aetherteam/nitrogen/capability/INBTSynchable.java @@ -6,8 +6,8 @@ import net.minecraft.resources.ResourceKey; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.level.Level; -import net.minecraftforge.common.util.INBTSerializable; -import net.minecraftforge.network.simple.SimpleChannel; +import net.neoforged.neoforge.common.util.INBTSerializable; +import net.neoforged.neoforge.network.simple.SimpleChannel; import org.apache.commons.lang3.tuple.Triple; import oshi.util.tuples.Quintet; diff --git a/src/main/java/com/aetherteam/nitrogen/client/renderer/NitrogenRenderers.java b/src/main/java/com/aetherteam/nitrogen/client/renderer/NitrogenRenderers.java index b6d7e69..5d697c1 100644 --- a/src/main/java/com/aetherteam/nitrogen/client/renderer/NitrogenRenderers.java +++ b/src/main/java/com/aetherteam/nitrogen/client/renderer/NitrogenRenderers.java @@ -3,8 +3,8 @@ import com.aetherteam.nitrogen.client.renderer.blockentity.NitrogenBlockEntityWithoutLevelRenderer; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer; -import net.minecraftforge.client.extensions.common.IClientItemExtensions; -import net.minecraftforge.common.util.Lazy; +import net.neoforged.neoforge.client.extensions.common.IClientItemExtensions; +import net.neoforged.neoforge.common.util.Lazy; public class NitrogenRenderers { public static final Lazy blockEntityWithoutLevelRenderer = () -> diff --git a/src/main/java/com/aetherteam/nitrogen/data/providers/NitrogenBlockLootSubProvider.java b/src/main/java/com/aetherteam/nitrogen/data/providers/NitrogenBlockLootSubProvider.java index dfc5de7..274a6b7 100644 --- a/src/main/java/com/aetherteam/nitrogen/data/providers/NitrogenBlockLootSubProvider.java +++ b/src/main/java/com/aetherteam/nitrogen/data/providers/NitrogenBlockLootSubProvider.java @@ -12,7 +12,7 @@ import net.minecraft.world.level.storage.loot.functions.CopyNameFunction; import net.minecraft.world.level.storage.loot.predicates.MatchTool; import net.minecraft.world.level.storage.loot.providers.number.ConstantValue; -import net.minecraftforge.common.Tags; +import net.neoforged.neoforge.common.Tags; import java.util.Set; diff --git a/src/main/java/com/aetherteam/nitrogen/data/providers/NitrogenBlockStateProvider.java b/src/main/java/com/aetherteam/nitrogen/data/providers/NitrogenBlockStateProvider.java index f5874ae..12b428a 100644 --- a/src/main/java/com/aetherteam/nitrogen/data/providers/NitrogenBlockStateProvider.java +++ b/src/main/java/com/aetherteam/nitrogen/data/providers/NitrogenBlockStateProvider.java @@ -1,6 +1,7 @@ package com.aetherteam.nitrogen.data.providers; 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.*; @@ -8,9 +9,8 @@ import net.minecraft.world.level.block.state.properties.Property; import net.minecraft.world.level.block.state.properties.SlabType; import net.minecraft.world.level.block.state.properties.WallSide; -import net.minecraftforge.client.model.generators.*; -import net.minecraftforge.common.data.ExistingFileHelper; -import net.minecraftforge.registries.ForgeRegistries; +import net.neoforged.neoforge.client.model.generators.*; +import net.neoforged.neoforge.common.data.ExistingFileHelper; import java.util.Map; @@ -20,7 +20,7 @@ public NitrogenBlockStateProvider(PackOutput output, String id, ExistingFileHelp } public String name(Block block) { - ResourceLocation location = ForgeRegistries.BLOCKS.getKey(block); + ResourceLocation location = BuiltInRegistries.BLOCK.getKey(block); if (location != null) { return location.getPath(); } else { diff --git a/src/main/java/com/aetherteam/nitrogen/data/providers/NitrogenItemModelProvider.java b/src/main/java/com/aetherteam/nitrogen/data/providers/NitrogenItemModelProvider.java index c5c6976..cce5886 100644 --- a/src/main/java/com/aetherteam/nitrogen/data/providers/NitrogenItemModelProvider.java +++ b/src/main/java/com/aetherteam/nitrogen/data/providers/NitrogenItemModelProvider.java @@ -2,6 +2,7 @@ import com.aetherteam.nitrogen.Nitrogen; import net.minecraft.core.Direction; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.data.PackOutput; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; @@ -10,10 +11,9 @@ import net.minecraft.world.item.armortrim.TrimMaterial; import net.minecraft.world.item.armortrim.TrimMaterials; import net.minecraft.world.level.block.Block; -import net.minecraftforge.client.model.generators.ItemModelBuilder; -import net.minecraftforge.client.model.generators.ItemModelProvider; -import net.minecraftforge.common.data.ExistingFileHelper; -import net.minecraftforge.registries.ForgeRegistries; +import net.neoforged.neoforge.client.model.generators.ItemModelBuilder; +import net.neoforged.neoforge.client.model.generators.ItemModelProvider; +import net.neoforged.neoforge.common.data.ExistingFileHelper; import java.util.List; @@ -25,7 +25,7 @@ public NitrogenItemModelProvider(PackOutput output, String id, ExistingFileHelpe } public String blockName(Block block) { - ResourceLocation location = ForgeRegistries.BLOCKS.getKey(block); + ResourceLocation location = BuiltInRegistries.BLOCK.getKey(block); if (location != null) { return location.getPath(); } else { @@ -34,7 +34,7 @@ public String blockName(Block block) { } public String itemName(Item item) { - ResourceLocation location = ForgeRegistries.ITEMS.getKey(item); + ResourceLocation location = BuiltInRegistries.ITEM.getKey(item); if (location != null) { return location.getPath(); } else { diff --git a/src/main/java/com/aetherteam/nitrogen/data/providers/NitrogenLanguageProvider.java b/src/main/java/com/aetherteam/nitrogen/data/providers/NitrogenLanguageProvider.java index 6abb0c3..7743d96 100644 --- a/src/main/java/com/aetherteam/nitrogen/data/providers/NitrogenLanguageProvider.java +++ b/src/main/java/com/aetherteam/nitrogen/data/providers/NitrogenLanguageProvider.java @@ -1,5 +1,6 @@ package com.aetherteam.nitrogen.data.providers; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.data.PackOutput; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; @@ -9,8 +10,7 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.levelgen.structure.Structure; -import net.minecraftforge.common.data.LanguageProvider; -import net.minecraftforge.registries.ForgeRegistries; +import net.neoforged.neoforge.common.data.LanguageProvider; import java.util.function.Supplier; @@ -43,7 +43,7 @@ public void addStructure(ResourceKey structure, String name) { } public void addContainerType(Supplier> key, String name) { - ResourceLocation location = ForgeRegistries.MENU_TYPES.getKey(key.get()); + ResourceLocation location = BuiltInRegistries.MENU.getKey(key.get()); if (location != null) { this.add("menu." + location.toString().replace(":", "."), name); } diff --git a/src/main/java/com/aetherteam/nitrogen/data/providers/NitrogenRecipeProvider.java b/src/main/java/com/aetherteam/nitrogen/data/providers/NitrogenRecipeProvider.java index 78c8fe3..9f0cba4 100644 --- a/src/main/java/com/aetherteam/nitrogen/data/providers/NitrogenRecipeProvider.java +++ b/src/main/java/com/aetherteam/nitrogen/data/providers/NitrogenRecipeProvider.java @@ -1,6 +1,7 @@ package com.aetherteam.nitrogen.data.providers; import com.aetherteam.nitrogen.recipe.BlockPropertyPair; +import net.minecraft.core.HolderLookup; import net.minecraft.data.PackOutput; import net.minecraft.data.recipes.*; import net.minecraft.resources.ResourceLocation; @@ -12,14 +13,15 @@ import net.minecraft.world.level.block.state.properties.Property; import java.util.Map; +import java.util.concurrent.CompletableFuture; import java.util.function.Consumer; import java.util.function.Supplier; public abstract class NitrogenRecipeProvider extends RecipeProvider { protected final String id; - public NitrogenRecipeProvider(PackOutput output, String id) { - super(output); + public NitrogenRecipeProvider(PackOutput output, CompletableFuture lookupProvider, String id) { + super(output, lookupProvider); this.id = id; } @@ -27,9 +29,9 @@ protected ResourceLocation name(String name) { return new ResourceLocation(this.id, name); } - protected void oreBlockStorageRecipesRecipesWithCustomUnpacking(Consumer consumer, RecipeCategory itemCategory, ItemLike item, RecipeCategory blockCategory, ItemLike block, String itemRecipeName, String itemGroup) { - ShapelessRecipeBuilder.shapeless(itemCategory, item, 9).requires(block).group(itemGroup).unlockedBy(getHasName(block), has(block)).save(consumer, this.name(itemRecipeName)); - ShapedRecipeBuilder.shaped(blockCategory, block).define('#', item).pattern("###").pattern("###").pattern("###").unlockedBy(getHasName(item), has(item)).save(consumer, this.name(getSimpleRecipeName(block))); + protected void oreBlockStorageRecipesRecipesWithCustomUnpacking(RecipeOutput output, RecipeCategory itemCategory, ItemLike item, RecipeCategory blockCategory, ItemLike block, String itemRecipeName, String itemGroup) { + ShapelessRecipeBuilder.shapeless(itemCategory, item, 9).requires(block).group(itemGroup).unlockedBy(getHasName(block), has(block)).save(output, this.name(itemRecipeName)); + ShapedRecipeBuilder.shaped(blockCategory, block).define('#', item).pattern("###").pattern("###").pattern("###").unlockedBy(getHasName(item), has(item)).save(output, this.name(getSimpleRecipeName(block))); } protected ShapedRecipeBuilder fence(Supplier fence, Supplier material, Ingredient sticks) { @@ -324,12 +326,12 @@ protected SimpleCookingRecipeBuilder blastingOreRecipe(ItemLike result, ItemLike .unlockedBy(getHasName(ingredient), has(ingredient)); } - protected void stonecuttingRecipe(Consumer consumer, RecipeCategory category, ItemLike item, ItemLike ingredient) { - this.stonecuttingRecipe(consumer, category, item, ingredient, 1); + protected void stonecuttingRecipe(RecipeOutput output, RecipeCategory category, ItemLike item, ItemLike ingredient) { + this.stonecuttingRecipe(output, category, item, ingredient, 1); } - protected void stonecuttingRecipe(Consumer consumer, RecipeCategory category, ItemLike item, ItemLike ingredient, int count) { - SingleItemRecipeBuilder.stonecutting(Ingredient.of(ingredient), category, item, count).unlockedBy(getHasName(ingredient), has(ingredient)).save(consumer, this.name(getConversionRecipeName(item, ingredient) + "_stonecutting")); + protected void stonecuttingRecipe(RecipeOutput output, RecipeCategory category, ItemLike item, ItemLike ingredient, int count) { + SingleItemRecipeBuilder.stonecutting(Ingredient.of(ingredient), category, item, count).unlockedBy(getHasName(ingredient), has(ingredient)).save(output, this.name(getConversionRecipeName(item, ingredient) + "_stonecutting")); } protected BlockPropertyPair pair(Block resultBlock, Map, Comparable> resultProperties) { diff --git a/src/main/java/com/aetherteam/nitrogen/integration/jei/BlockStateRenderer.java b/src/main/java/com/aetherteam/nitrogen/integration/jei/BlockStateRenderer.java index cbbe8bc..442ccac 100644 --- a/src/main/java/com/aetherteam/nitrogen/integration/jei/BlockStateRenderer.java +++ b/src/main/java/com/aetherteam/nitrogen/integration/jei/BlockStateRenderer.java @@ -1,195 +1,195 @@ package com.aetherteam.nitrogen.integration.jei; -import com.aetherteam.nitrogen.Nitrogen; -import com.aetherteam.nitrogen.recipe.BlockPropertyPair; -import com.aetherteam.nitrogen.recipe.BlockStateRecipeUtil; -import com.google.common.collect.Lists; -import com.mojang.blaze3d.platform.Lighting; -import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.math.Axis; -import mezz.jei.api.ingredients.IIngredientRenderer; -import mezz.jei.common.platform.IPlatformRenderHelper; -import mezz.jei.common.platform.Services; -import mezz.jei.common.util.ErrorUtil; -import net.minecraft.ChatFormatting; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Font; -import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.renderer.LightTexture; -import net.minecraft.client.renderer.MultiBufferSource; -import net.minecraft.client.renderer.RenderType; -import net.minecraft.client.renderer.Sheets; -import net.minecraft.client.renderer.block.BlockRenderDispatcher; -import net.minecraft.client.renderer.block.ModelBlockRenderer; -import net.minecraft.client.renderer.texture.OverlayTexture; -import net.minecraft.client.resources.model.BakedModel; -import net.minecraft.core.BlockPos; -import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.MutableComponent; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.TooltipFlag; -import net.minecraft.world.level.BlockGetter; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.state.properties.Property; -import net.minecraft.world.level.material.FluidState; -import net.minecraft.world.level.material.Fluids; -import net.minecraftforge.client.model.data.ModelData; -import net.minecraftforge.registries.ForgeRegistries; -import org.jetbrains.annotations.Nullable; -import org.joml.Vector3f; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -public record BlockStateRenderer(BlockPropertyPair... pairs) implements IIngredientRenderer { - @Override - public void render(GuiGraphics guiGraphics, @Nullable ItemStack ingredient) { - PoseStack poseStack = guiGraphics.pose(); - Minecraft minecraft = Minecraft.getInstance(); - BlockRenderDispatcher blockRenderDispatcher = minecraft.getBlockRenderer(); - - BlockPropertyPair pair = this.getMatchingPair(ingredient); - - if (pair.block() != null && pair.properties() != null && minecraft.level != null) { - BlockState blockState = pair.block().defaultBlockState(); - for (Map.Entry, Comparable> propertyEntry : pair.properties().entrySet()) { - blockState = BlockStateRecipeUtil.setHelper(propertyEntry, blockState); - } - - poseStack.pushPose(); - - poseStack.translate(15.0F, 12.33F, 5.0F); - poseStack.mulPose(Axis.XP.rotationDegrees(-30.0F)); - poseStack.mulPose(Axis.YP.rotationDegrees(45.0F)); - poseStack.scale(-9.9F, -9.9F, -9.9F); - - RenderSystem.setupGui3DDiffuseLighting((new Vector3f(0.4F, 0.0F, 1.0F)).normalize(), (new Vector3f(-0.4F, 1.0F, -0.2F)).normalize()); - - ModelBlockRenderer modelBlockRenderer = blockRenderDispatcher.getModelRenderer(); - MultiBufferSource.BufferSource bufferSource = minecraft.renderBuffers().bufferSource(); - BakedModel model = blockRenderDispatcher.getBlockModel(blockState); - RenderType renderType = model.getRenderTypes(blockState, minecraft.level.getRandom(), ModelData.EMPTY).asList().get(0); - modelBlockRenderer.tesselateBlock(new FakeBlockLevel(blockState), model, blockState, BlockPos.ZERO, poseStack, bufferSource.getBuffer(Sheets.translucentCullBlockSheet()), false, minecraft.level.getRandom(), LightTexture.FULL_BRIGHT, OverlayTexture.NO_OVERLAY, ModelData.EMPTY, renderType); - bufferSource.endBatch(); - - Lighting.setupFor3DItems(); - - poseStack.popPose(); - } - } - - @Override - public List getTooltip(ItemStack ingredient, TooltipFlag tooltipFlag) { - Minecraft minecraft = Minecraft.getInstance(); - Player player = minecraft.player; - try { - List list = Lists.newArrayList(); - - BlockPropertyPair pair = this.getMatchingPair(ingredient); - Block block = pair.block(); - Map, Comparable> properties = pair.properties(); - - if (block != null && properties != null) { - // Display block name. - MutableComponent mutablecomponent = Component.empty().append(block.getName()).withStyle(ingredient.getRarity().getStyleModifier()); - list.add(mutablecomponent); - if (tooltipFlag.isAdvanced()) { - ResourceLocation blockKey = ForgeRegistries.BLOCKS.getKey(block); - if (blockKey != null) { - list.add(Component.literal(blockKey.toString()).withStyle(ChatFormatting.DARK_GRAY)); - } - } - // Display whether this blockstate is enabled. - if (player != null && !ingredient.getItem().isEnabled(player.level().enabledFeatures())) { - list.add(Component.translatable("item.disabled").withStyle(ChatFormatting.RED)); - } - // Display block properties. - if (!properties.isEmpty()) { - list.add(Component.translatable("gui.aether.jei.properties.tooltip").withStyle(ChatFormatting.GRAY)); - for (Map.Entry, Comparable> entry : properties.entrySet()) { - list.add(Component.literal(entry.getKey().getName() + ": " + entry.getValue().toString()).withStyle(ChatFormatting.DARK_GRAY)); - } - } - } - return list; - } catch (RuntimeException | LinkageError e) { - String itemStackInfo = ErrorUtil.getItemStackInfo(ingredient); - Nitrogen.LOGGER.error("Failed to get tooltip: {}", itemStackInfo, e); - List list = new ArrayList<>(); - MutableComponent crash = Component.translatable("jei.tooltip.error.crash"); - list.add(crash.withStyle(ChatFormatting.RED)); - return list; - } - } - - @Override - public Font getFontRenderer(Minecraft minecraft, ItemStack ingredient) { - IPlatformRenderHelper renderHelper = Services.PLATFORM.getRenderHelper(); - return renderHelper.getFontRenderer(minecraft, ingredient); - } - - @Override - public int getWidth() { - return 16; - } - - @Override - public int getHeight() { - return 16; - } - - /** - * Warning for "deprecation" is suppressed because the non-sensitive version of {@link net.minecraft.world.level.block.Block#getCloneItemStack(BlockGetter, BlockPos, BlockState)} is needed in this context. - */ - @SuppressWarnings("deprecation") - private BlockPropertyPair getMatchingPair(ItemStack ingredient) { - Map, Comparable>> pairsMap = Stream.of(this.pairs).collect(Collectors.toMap(BlockPropertyPair::block, BlockPropertyPair::properties)); - Block block = null; - Map, Comparable> propertiesMap = null; - if (Minecraft.getInstance().level != null) { - for (Map.Entry, Comparable>> entry : pairsMap.entrySet()) { - ItemStack stack = entry.getKey().getCloneItemStack(Minecraft.getInstance().level, BlockPos.ZERO, entry.getKey().defaultBlockState()); - stack = stack.isEmpty() ? new ItemStack(Blocks.STONE) : stack; - if (stack.getItem() == ingredient.getItem()) { - block = entry.getKey(); - propertiesMap = entry.getValue(); - } - } - } - return BlockPropertyPair.of(block, propertiesMap); - } - - /** - * A fake level used for rendering. - */ - private static class FakeBlockLevel extends FakeLevel { - private final BlockState blockState; - - public FakeBlockLevel(BlockState blockState) { - this.blockState = blockState; - } - - @Override - public BlockState getBlockState(BlockPos pos) { - if (pos.equals(BlockPos.ZERO)) { - return this.blockState; - } else { - return Blocks.AIR.defaultBlockState(); - } - } - - @Override - public FluidState getFluidState(BlockPos pos) { - return Fluids.EMPTY.defaultFluidState(); - } - } -} +//import com.aetherteam.nitrogen.Nitrogen; +//import com.aetherteam.nitrogen.recipe.BlockPropertyPair; +//import com.aetherteam.nitrogen.recipe.BlockStateRecipeUtil; +//import com.google.common.collect.Lists; +//import com.mojang.blaze3d.platform.Lighting; +//import com.mojang.blaze3d.systems.RenderSystem; +//import com.mojang.blaze3d.vertex.PoseStack; +//import com.mojang.math.Axis; +//import mezz.jei.api.ingredients.IIngredientRenderer; +//import mezz.jei.common.platform.IPlatformRenderHelper; +//import mezz.jei.common.platform.Services; +//import mezz.jei.common.util.ErrorUtil; +//import net.minecraft.ChatFormatting; +//import net.minecraft.client.Minecraft; +//import net.minecraft.client.gui.Font; +//import net.minecraft.client.gui.GuiGraphics; +//import net.minecraft.client.renderer.LightTexture; +//import net.minecraft.client.renderer.MultiBufferSource; +//import net.minecraft.client.renderer.RenderType; +//import net.minecraft.client.renderer.Sheets; +//import net.minecraft.client.renderer.block.BlockRenderDispatcher; +//import net.minecraft.client.renderer.block.ModelBlockRenderer; +//import net.minecraft.client.renderer.texture.OverlayTexture; +//import net.minecraft.client.resources.model.BakedModel; +//import net.minecraft.core.BlockPos; +//import net.minecraft.network.chat.Component; +//import net.minecraft.network.chat.MutableComponent; +//import net.minecraft.resources.ResourceLocation; +//import net.minecraft.world.entity.player.Player; +//import net.minecraft.world.item.ItemStack; +//import net.minecraft.world.item.TooltipFlag; +//import net.minecraft.world.level.BlockGetter; +//import net.minecraft.world.level.block.Block; +//import net.minecraft.world.level.block.Blocks; +//import net.minecraft.world.level.block.state.BlockState; +//import net.minecraft.world.level.block.state.properties.Property; +//import net.minecraft.world.level.material.FluidState; +//import net.minecraft.world.level.material.Fluids; +//import net.neoforged.neoforge.client.model.data.ModelData; +//import net.neoforged.neoforge.registries.ForgeRegistries; +//import org.jetbrains.annotations.Nullable; +//import org.joml.Vector3f; +// +//import java.util.ArrayList; +//import java.util.List; +//import java.util.Map; +//import java.util.stream.Collectors; +//import java.util.stream.Stream; +// +//public record BlockStateRenderer(BlockPropertyPair... pairs) implements IIngredientRenderer { +// @Override +// public void render(GuiGraphics guiGraphics, @Nullable ItemStack ingredient) { +// PoseStack poseStack = guiGraphics.pose(); +// Minecraft minecraft = Minecraft.getInstance(); +// BlockRenderDispatcher blockRenderDispatcher = minecraft.getBlockRenderer(); +// +// BlockPropertyPair pair = this.getMatchingPair(ingredient); +// +// if (pair.block() != null && pair.properties() != null && minecraft.level != null) { +// BlockState blockState = pair.block().defaultBlockState(); +// for (Map.Entry, Comparable> propertyEntry : pair.properties().entrySet()) { +// blockState = BlockStateRecipeUtil.setHelper(propertyEntry, blockState); +// } +// +// poseStack.pushPose(); +// +// poseStack.translate(15.0F, 12.33F, 5.0F); +// poseStack.mulPose(Axis.XP.rotationDegrees(-30.0F)); +// poseStack.mulPose(Axis.YP.rotationDegrees(45.0F)); +// poseStack.scale(-9.9F, -9.9F, -9.9F); +// +// RenderSystem.setupGui3DDiffuseLighting((new Vector3f(0.4F, 0.0F, 1.0F)).normalize(), (new Vector3f(-0.4F, 1.0F, -0.2F)).normalize()); +// +// ModelBlockRenderer modelBlockRenderer = blockRenderDispatcher.getModelRenderer(); +// MultiBufferSource.BufferSource bufferSource = minecraft.renderBuffers().bufferSource(); +// BakedModel model = blockRenderDispatcher.getBlockModel(blockState); +// RenderType renderType = model.getRenderTypes(blockState, minecraft.level.getRandom(), ModelData.EMPTY).asList().get(0); +// modelBlockRenderer.tesselateBlock(new FakeBlockLevel(blockState), model, blockState, BlockPos.ZERO, poseStack, bufferSource.getBuffer(Sheets.translucentCullBlockSheet()), false, minecraft.level.getRandom(), LightTexture.FULL_BRIGHT, OverlayTexture.NO_OVERLAY, ModelData.EMPTY, renderType); +// bufferSource.endBatch(); +// +// Lighting.setupFor3DItems(); +// +// poseStack.popPose(); +// } +// } +// +// @Override +// public List getTooltip(ItemStack ingredient, TooltipFlag tooltipFlag) { +// Minecraft minecraft = Minecraft.getInstance(); +// Player player = minecraft.player; +// try { +// List list = Lists.newArrayList(); +// +// BlockPropertyPair pair = this.getMatchingPair(ingredient); +// Block block = pair.block(); +// Map, Comparable> properties = pair.properties(); +// +// if (block != null && properties != null) { +// // Display block name. +// MutableComponent mutablecomponent = Component.empty().append(block.getName()).withStyle(ingredient.getRarity().getStyleModifier()); +// list.add(mutablecomponent); +// if (tooltipFlag.isAdvanced()) { +// ResourceLocation blockKey = ForgeRegistries.BLOCKS.getKey(block); +// if (blockKey != null) { +// list.add(Component.literal(blockKey.toString()).withStyle(ChatFormatting.DARK_GRAY)); +// } +// } +// // Display whether this blockstate is enabled. +// if (player != null && !ingredient.getItem().isEnabled(player.level().enabledFeatures())) { +// list.add(Component.translatable("item.disabled").withStyle(ChatFormatting.RED)); +// } +// // Display block properties. +// if (!properties.isEmpty()) { +// list.add(Component.translatable("gui.aether.jei.properties.tooltip").withStyle(ChatFormatting.GRAY)); +// for (Map.Entry, Comparable> entry : properties.entrySet()) { +// list.add(Component.literal(entry.getKey().getName() + ": " + entry.getValue().toString()).withStyle(ChatFormatting.DARK_GRAY)); +// } +// } +// } +// return list; +// } catch (RuntimeException | LinkageError e) { +// String itemStackInfo = ErrorUtil.getItemStackInfo(ingredient); +// Nitrogen.LOGGER.error("Failed to get tooltip: {}", itemStackInfo, e); +// List list = new ArrayList<>(); +// MutableComponent crash = Component.translatable("jei.tooltip.error.crash"); +// list.add(crash.withStyle(ChatFormatting.RED)); +// return list; +// } +// } +// +// @Override +// public Font getFontRenderer(Minecraft minecraft, ItemStack ingredient) { +// IPlatformRenderHelper renderHelper = Services.PLATFORM.getRenderHelper(); +// return renderHelper.getFontRenderer(minecraft, ingredient); +// } +// +// @Override +// public int getWidth() { +// return 16; +// } +// +// @Override +// public int getHeight() { +// return 16; +// } +// +// /** +// * Warning for "deprecation" is suppressed because the non-sensitive version of {@link net.minecraft.world.level.block.Block#getCloneItemStack(BlockGetter, BlockPos, BlockState)} is needed in this context. +// */ +// @SuppressWarnings("deprecation") +// private BlockPropertyPair getMatchingPair(ItemStack ingredient) { +// Map, Comparable>> pairsMap = Stream.of(this.pairs).collect(Collectors.toMap(BlockPropertyPair::block, BlockPropertyPair::properties)); +// Block block = null; +// Map, Comparable> propertiesMap = null; +// if (Minecraft.getInstance().level != null) { +// for (Map.Entry, Comparable>> entry : pairsMap.entrySet()) { +// ItemStack stack = entry.getKey().getCloneItemStack(Minecraft.getInstance().level, BlockPos.ZERO, entry.getKey().defaultBlockState()); +// stack = stack.isEmpty() ? new ItemStack(Blocks.STONE) : stack; +// if (stack.getItem() == ingredient.getItem()) { +// block = entry.getKey(); +// propertiesMap = entry.getValue(); +// } +// } +// } +// return BlockPropertyPair.of(block, propertiesMap); +// } +// +// /** +// * A fake level used for rendering. +// */ +// private static class FakeBlockLevel extends FakeLevel { +// private final BlockState blockState; +// +// public FakeBlockLevel(BlockState blockState) { +// this.blockState = blockState; +// } +// +// @Override +// public BlockState getBlockState(BlockPos pos) { +// if (pos.equals(BlockPos.ZERO)) { +// return this.blockState; +// } else { +// return Blocks.AIR.defaultBlockState(); +// } +// } +// +// @Override +// public FluidState getFluidState(BlockPos pos) { +// return Fluids.EMPTY.defaultFluidState(); +// } +// } +//} diff --git a/src/main/java/com/aetherteam/nitrogen/integration/jei/FluidStateRenderer.java b/src/main/java/com/aetherteam/nitrogen/integration/jei/FluidStateRenderer.java index 8a11fe1..46804d5 100644 --- a/src/main/java/com/aetherteam/nitrogen/integration/jei/FluidStateRenderer.java +++ b/src/main/java/com/aetherteam/nitrogen/integration/jei/FluidStateRenderer.java @@ -1,109 +1,109 @@ package com.aetherteam.nitrogen.integration.jei; -import com.aetherteam.nitrogen.Nitrogen; -import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.BufferBuilder; -import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.blaze3d.vertex.Tesselator; -import com.mojang.math.Axis; -import mezz.jei.api.ingredients.IIngredientRenderer; -import mezz.jei.api.ingredients.IIngredientTypeWithSubtypes; -import mezz.jei.common.platform.IPlatformFluidHelperInternal; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.renderer.ItemBlockRenderTypes; -import net.minecraft.client.renderer.RenderType; -import net.minecraft.client.renderer.block.BlockRenderDispatcher; -import net.minecraft.core.BlockPos; -import net.minecraft.network.chat.Component; -import net.minecraft.world.item.TooltipFlag; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.material.Fluid; -import net.minecraft.world.level.material.FluidState; -import net.minecraft.world.level.material.Fluids; - -import java.util.ArrayList; -import java.util.List; - -public record FluidStateRenderer(IPlatformFluidHelperInternal fluidHelper) implements IIngredientRenderer { - @Override - public void render(GuiGraphics guiGraphics, T ingredient) { - PoseStack poseStack = guiGraphics.pose(); - Minecraft minecraft = Minecraft.getInstance(); - BlockRenderDispatcher blockRenderDispatcher = minecraft.getBlockRenderer(); - - poseStack.pushPose(); - - poseStack.translate(15.0F, 12.33F, 0.0F); - poseStack.mulPose(Axis.XP.rotationDegrees(-30.0F)); - poseStack.mulPose(Axis.YP.rotationDegrees(45.0F)); - poseStack.scale(-9.9F, -9.9F, -9.9F); - - IIngredientTypeWithSubtypes type = this.fluidHelper.getFluidIngredientType(); - Fluid fluidType = type.getBase(ingredient); - FluidState fluidState = fluidType.defaultFluidState(); - RenderType renderType = ItemBlockRenderTypes.getRenderLayer(fluidState); - PoseStack worldStack = RenderSystem.getModelViewStack(); - - renderType.setupRenderState(); - worldStack.pushPose(); - worldStack.mulPoseMatrix(poseStack.last().pose()); - RenderSystem.applyModelViewMatrix(); - - Tesselator tesselator = Tesselator.getInstance(); - BufferBuilder builder = tesselator.getBuilder(); - builder.begin(renderType.mode(), renderType.format()); - blockRenderDispatcher.renderLiquid(BlockPos.ZERO, new FakeFluidLevel(fluidState), builder, fluidState.createLegacyBlock(), fluidState); - if (builder.building()) { - tesselator.end(); - } - - renderType.clearRenderState(); - worldStack.popPose(); - RenderSystem.applyModelViewMatrix(); - - poseStack.popPose(); - } - - @Override - public List getTooltip(T ingredient, TooltipFlag tooltipFlag) { - try { - return this.fluidHelper.getTooltip(ingredient, tooltipFlag); - } catch (RuntimeException | LinkageError e) { - Component displayName = this.fluidHelper.getDisplayName(ingredient); - Nitrogen.LOGGER.error("Failed to get tooltip for fluid: " + displayName, e); - return new ArrayList<>(); - } - } - - /** - * A fake level used for rendering. - */ - private static class FakeFluidLevel extends FakeLevel { - private final FluidState fluidState; - - public FakeFluidLevel(FluidState fluidState) { - this.fluidState = fluidState; - } - - @Override - public BlockState getBlockState(BlockPos pos) { - if (pos.equals(BlockPos.ZERO)) { - return this.fluidState.createLegacyBlock(); - } else { - return Blocks.AIR.defaultBlockState(); - } - } - - @Override - public FluidState getFluidState(BlockPos pos) { - if (pos.equals(BlockPos.ZERO)) { - return this.fluidState; - } else { - return Fluids.EMPTY.defaultFluidState(); - } - } - } -} +//import com.aetherteam.nitrogen.Nitrogen; +//import com.mojang.blaze3d.systems.RenderSystem; +//import com.mojang.blaze3d.vertex.BufferBuilder; +//import com.mojang.blaze3d.vertex.PoseStack; +//import com.mojang.blaze3d.vertex.Tesselator; +//import com.mojang.math.Axis; +//import mezz.jei.api.ingredients.IIngredientRenderer; +//import mezz.jei.api.ingredients.IIngredientTypeWithSubtypes; +//import mezz.jei.common.platform.IPlatformFluidHelperInternal; +//import net.minecraft.client.Minecraft; +//import net.minecraft.client.gui.GuiGraphics; +//import net.minecraft.client.renderer.ItemBlockRenderTypes; +//import net.minecraft.client.renderer.RenderType; +//import net.minecraft.client.renderer.block.BlockRenderDispatcher; +//import net.minecraft.core.BlockPos; +//import net.minecraft.network.chat.Component; +//import net.minecraft.world.item.TooltipFlag; +//import net.minecraft.world.level.block.Blocks; +//import net.minecraft.world.level.block.state.BlockState; +//import net.minecraft.world.level.material.Fluid; +//import net.minecraft.world.level.material.FluidState; +//import net.minecraft.world.level.material.Fluids; +// +//import java.util.ArrayList; +//import java.util.List; +// +//public record FluidStateRenderer(IPlatformFluidHelperInternal fluidHelper) implements IIngredientRenderer { +// @Override +// public void render(GuiGraphics guiGraphics, T ingredient) { +// PoseStack poseStack = guiGraphics.pose(); +// Minecraft minecraft = Minecraft.getInstance(); +// BlockRenderDispatcher blockRenderDispatcher = minecraft.getBlockRenderer(); +// +// poseStack.pushPose(); +// +// poseStack.translate(15.0F, 12.33F, 0.0F); +// poseStack.mulPose(Axis.XP.rotationDegrees(-30.0F)); +// poseStack.mulPose(Axis.YP.rotationDegrees(45.0F)); +// poseStack.scale(-9.9F, -9.9F, -9.9F); +// +// IIngredientTypeWithSubtypes type = this.fluidHelper.getFluidIngredientType(); +// Fluid fluidType = type.getBase(ingredient); +// FluidState fluidState = fluidType.defaultFluidState(); +// RenderType renderType = ItemBlockRenderTypes.getRenderLayer(fluidState); +// PoseStack worldStack = RenderSystem.getModelViewStack(); +// +// renderType.setupRenderState(); +// worldStack.pushPose(); +// worldStack.mulPoseMatrix(poseStack.last().pose()); +// RenderSystem.applyModelViewMatrix(); +// +// Tesselator tesselator = Tesselator.getInstance(); +// BufferBuilder builder = tesselator.getBuilder(); +// builder.begin(renderType.mode(), renderType.format()); +// blockRenderDispatcher.renderLiquid(BlockPos.ZERO, new FakeFluidLevel(fluidState), builder, fluidState.createLegacyBlock(), fluidState); +// if (builder.building()) { +// tesselator.end(); +// } +// +// renderType.clearRenderState(); +// worldStack.popPose(); +// RenderSystem.applyModelViewMatrix(); +// +// poseStack.popPose(); +// } +// +// @Override +// public List getTooltip(T ingredient, TooltipFlag tooltipFlag) { +// try { +// return this.fluidHelper.getTooltip(ingredient, tooltipFlag); +// } catch (RuntimeException | LinkageError e) { +// Component displayName = this.fluidHelper.getDisplayName(ingredient); +// Nitrogen.LOGGER.error("Failed to get tooltip for fluid: " + displayName, e); +// return new ArrayList<>(); +// } +// } +// +// /** +// * A fake level used for rendering. +// */ +// private static class FakeFluidLevel extends FakeLevel { +// private final FluidState fluidState; +// +// public FakeFluidLevel(FluidState fluidState) { +// this.fluidState = fluidState; +// } +// +// @Override +// public BlockState getBlockState(BlockPos pos) { +// if (pos.equals(BlockPos.ZERO)) { +// return this.fluidState.createLegacyBlock(); +// } else { +// return Blocks.AIR.defaultBlockState(); +// } +// } +// +// @Override +// public FluidState getFluidState(BlockPos pos) { +// if (pos.equals(BlockPos.ZERO)) { +// return this.fluidState; +// } else { +// return Fluids.EMPTY.defaultFluidState(); +// } +// } +// } +//} diff --git a/src/main/java/com/aetherteam/nitrogen/integration/jei/categories/AbstractRecipeCategory.java b/src/main/java/com/aetherteam/nitrogen/integration/jei/categories/AbstractRecipeCategory.java index a332667..21187d2 100644 --- a/src/main/java/com/aetherteam/nitrogen/integration/jei/categories/AbstractRecipeCategory.java +++ b/src/main/java/com/aetherteam/nitrogen/integration/jei/categories/AbstractRecipeCategory.java @@ -1,44 +1,44 @@ package com.aetherteam.nitrogen.integration.jei.categories; -import mezz.jei.api.gui.drawable.IDrawable; -import mezz.jei.api.recipe.RecipeType; -import mezz.jei.api.recipe.category.IRecipeCategory; -import net.minecraft.resources.ResourceLocation; - -/** - * A basic abstract class for JEI recipe categories. - */ -public abstract class AbstractRecipeCategory implements IRecipeCategory { - protected final String id; - protected final ResourceLocation uid; - protected final IDrawable background; - protected final IDrawable icon; - protected final RecipeType recipeType; - - public AbstractRecipeCategory(String id, ResourceLocation uid, IDrawable background, IDrawable icon, RecipeType recipeType) { - this.id = id; - this.uid = uid; - this.background = background; - this.icon = icon; - this.recipeType = recipeType; - } - - @Override - public IDrawable getBackground() { - return this.background; - } - - @Override - public IDrawable getIcon() { - return this.icon; - } - - public ResourceLocation getUid() { - return this.uid; - } - - @Override - public RecipeType getRecipeType() { - return this.recipeType; - } -} +//import mezz.jei.api.gui.drawable.IDrawable; +//import mezz.jei.api.recipe.RecipeType; +//import mezz.jei.api.recipe.category.IRecipeCategory; +//import net.minecraft.resources.ResourceLocation; +// +///** +// * A basic abstract class for JEI recipe categories. +// */ +//public abstract class AbstractRecipeCategory implements IRecipeCategory { +// protected final String id; +// protected final ResourceLocation uid; +// protected final IDrawable background; +// protected final IDrawable icon; +// protected final RecipeType recipeType; +// +// public AbstractRecipeCategory(String id, ResourceLocation uid, IDrawable background, IDrawable icon, RecipeType recipeType) { +// this.id = id; +// this.uid = uid; +// this.background = background; +// this.icon = icon; +// this.recipeType = recipeType; +// } +// +// @Override +// public IDrawable getBackground() { +// return this.background; +// } +// +// @Override +// public IDrawable getIcon() { +// return this.icon; +// } +// +// public ResourceLocation getUid() { +// return this.uid; +// } +// +// @Override +// public RecipeType getRecipeType() { +// return this.recipeType; +// } +//} diff --git a/src/main/java/com/aetherteam/nitrogen/integration/jei/categories/block/AbstractBlockStateRecipeCategory.java b/src/main/java/com/aetherteam/nitrogen/integration/jei/categories/block/AbstractBlockStateRecipeCategory.java index 2884419..3cc6b30 100644 --- a/src/main/java/com/aetherteam/nitrogen/integration/jei/categories/block/AbstractBlockStateRecipeCategory.java +++ b/src/main/java/com/aetherteam/nitrogen/integration/jei/categories/block/AbstractBlockStateRecipeCategory.java @@ -1,95 +1,95 @@ package com.aetherteam.nitrogen.integration.jei.categories.block; -import com.aetherteam.nitrogen.integration.jei.BlockStateRenderer; -import com.aetherteam.nitrogen.integration.jei.FluidStateRenderer; -import com.aetherteam.nitrogen.integration.jei.categories.AbstractRecipeCategory; -import com.aetherteam.nitrogen.recipe.BlockPropertyPair; -import com.aetherteam.nitrogen.recipe.BlockStateIngredient; -import com.aetherteam.nitrogen.recipe.BlockStateRecipeUtil; -import com.aetherteam.nitrogen.recipe.recipes.AbstractBlockStateRecipe; -import com.mojang.blaze3d.vertex.PoseStack; -import mezz.jei.api.constants.VanillaTypes; -import mezz.jei.api.gui.builder.IRecipeLayoutBuilder; -import mezz.jei.api.gui.drawable.IDrawable; -import mezz.jei.api.gui.ingredient.IRecipeSlotsView; -import mezz.jei.api.helpers.IPlatformFluidHelper; -import mezz.jei.api.recipe.IFocusGroup; -import mezz.jei.api.recipe.RecipeIngredientRole; -import mezz.jei.api.recipe.RecipeType; -import mezz.jei.common.platform.Services; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.core.BlockPos; -import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.BlockGetter; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.LiquidBlock; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.state.properties.Property; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -public abstract class AbstractBlockStateRecipeCategory extends AbstractRecipeCategory { - protected final IPlatformFluidHelper fluidHelper; - - public AbstractBlockStateRecipeCategory(String id, ResourceLocation uid, IDrawable background, IDrawable icon, RecipeType recipeType, IPlatformFluidHelper fluidHelper) { - super(id, uid, background, icon, recipeType); - this.fluidHelper = fluidHelper; - } - - @Override - public void setRecipe(IRecipeLayoutBuilder builder, T recipe, IFocusGroup focusGroup) { - BlockStateIngredient recipeIngredients = recipe.getIngredient(); - BlockPropertyPair recipeResult = recipe.getResult(); - BlockPropertyPair[] pairs = recipeIngredients.getPairs(); - if (pairs != null) { - // Sets up input slots. - List inputIngredients = new ArrayList<>(); - for (BlockPropertyPair pair : pairs) { - if (pair.block() instanceof LiquidBlock liquidBlock) { - inputIngredients.add(this.fluidHelper.create(liquidBlock.getFluid(), 1000)); - } else { - inputIngredients.add(this.setupIngredient(pair)); - } - } - builder.addSlot(RecipeIngredientRole.INPUT, 8, 6).addIngredientsUnsafe(inputIngredients).addTooltipCallback((recipeSlotView, tooltip) -> this.populateAdditionalInformation(recipe, tooltip)) - .setCustomRenderer(Services.PLATFORM.getFluidHelper().getFluidIngredientType(), new FluidStateRenderer(Services.PLATFORM.getFluidHelper())).setCustomRenderer(VanillaTypes.ITEM_STACK, new BlockStateRenderer(pairs)); - - // Sets up output slots. - Object outputIngredient; - if (recipeResult.block() instanceof LiquidBlock liquidBlock) { - outputIngredient = this.fluidHelper.create(liquidBlock.getFluid(), 1000); - } else { - outputIngredient = this.setupIngredient(recipeResult); - } - builder.addSlot(RecipeIngredientRole.OUTPUT, 60, 6).addIngredientsUnsafe(List.of(outputIngredient)) - .setCustomRenderer(Services.PLATFORM.getFluidHelper().getFluidIngredientType(), new FluidStateRenderer(Services.PLATFORM.getFluidHelper())).setCustomRenderer(VanillaTypes.ITEM_STACK, new BlockStateRenderer(recipeResult)); - } - } - - /** - * Warning for "deprecation" is suppressed because the non-sensitive version of {@link net.minecraft.world.level.block.Block#getCloneItemStack(BlockGetter, BlockPos, BlockState)} is needed in this context. - */ - @SuppressWarnings("deprecation") - private ItemStack setupIngredient(BlockPropertyPair recipeResult) { - ItemStack stack = ItemStack.EMPTY; - if (Minecraft.getInstance().level != null) { - BlockState resultState = recipeResult.block().defaultBlockState(); - for (Map.Entry, Comparable> propertyEntry : recipeResult.properties().entrySet()) { - resultState = BlockStateRecipeUtil.setHelper(propertyEntry, resultState); - } - stack = recipeResult.block().getCloneItemStack(Minecraft.getInstance().level, BlockPos.ZERO, resultState); - } - return stack.isEmpty() ? new ItemStack(Blocks.STONE) : stack; - } - - @Override - public void draw(T recipe, IRecipeSlotsView recipeSlotsView, GuiGraphics guiGraphics, double mouseX, double mouseY) { } - - protected void populateAdditionalInformation(T recipe, List tooltip) { } -} +//import com.aetherteam.nitrogen.integration.jei.BlockStateRenderer; +//import com.aetherteam.nitrogen.integration.jei.FluidStateRenderer; +//import com.aetherteam.nitrogen.integration.jei.categories.AbstractRecipeCategory; +//import com.aetherteam.nitrogen.recipe.BlockPropertyPair; +//import com.aetherteam.nitrogen.recipe.BlockStateIngredient; +//import com.aetherteam.nitrogen.recipe.BlockStateRecipeUtil; +//import com.aetherteam.nitrogen.recipe.recipes.AbstractBlockStateRecipe; +//import com.mojang.blaze3d.vertex.PoseStack; +//import mezz.jei.api.constants.VanillaTypes; +//import mezz.jei.api.gui.builder.IRecipeLayoutBuilder; +//import mezz.jei.api.gui.drawable.IDrawable; +//import mezz.jei.api.gui.ingredient.IRecipeSlotsView; +//import mezz.jei.api.helpers.IPlatformFluidHelper; +//import mezz.jei.api.recipe.IFocusGroup; +//import mezz.jei.api.recipe.RecipeIngredientRole; +//import mezz.jei.api.recipe.RecipeType; +//import mezz.jei.common.platform.Services; +//import net.minecraft.client.Minecraft; +//import net.minecraft.client.gui.GuiGraphics; +//import net.minecraft.core.BlockPos; +//import net.minecraft.network.chat.Component; +//import net.minecraft.resources.ResourceLocation; +//import net.minecraft.world.item.ItemStack; +//import net.minecraft.world.level.BlockGetter; +//import net.minecraft.world.level.block.Blocks; +//import net.minecraft.world.level.block.LiquidBlock; +//import net.minecraft.world.level.block.state.BlockState; +//import net.minecraft.world.level.block.state.properties.Property; +// +//import java.util.ArrayList; +//import java.util.List; +//import java.util.Map; +// +//public abstract class AbstractBlockStateRecipeCategory extends AbstractRecipeCategory { +// protected final IPlatformFluidHelper fluidHelper; +// +// public AbstractBlockStateRecipeCategory(String id, ResourceLocation uid, IDrawable background, IDrawable icon, RecipeType recipeType, IPlatformFluidHelper fluidHelper) { +// super(id, uid, background, icon, recipeType); +// this.fluidHelper = fluidHelper; +// } +// +// @Override +// public void setRecipe(IRecipeLayoutBuilder builder, T recipe, IFocusGroup focusGroup) { +// BlockStateIngredient recipeIngredients = recipe.getIngredient(); +// BlockPropertyPair recipeResult = recipe.getResult(); +// BlockPropertyPair[] pairs = recipeIngredients.getPairs(); +// if (pairs != null) { +// // Sets up input slots. +// List inputIngredients = new ArrayList<>(); +// for (BlockPropertyPair pair : pairs) { +// if (pair.block() instanceof LiquidBlock liquidBlock) { +// inputIngredients.add(this.fluidHelper.create(liquidBlock.getFluid(), 1000)); +// } else { +// inputIngredients.add(this.setupIngredient(pair)); +// } +// } +// builder.addSlot(RecipeIngredientRole.INPUT, 8, 6).addIngredientsUnsafe(inputIngredients).addTooltipCallback((recipeSlotView, tooltip) -> this.populateAdditionalInformation(recipe, tooltip)) +// .setCustomRenderer(Services.PLATFORM.getFluidHelper().getFluidIngredientType(), new FluidStateRenderer(Services.PLATFORM.getFluidHelper())).setCustomRenderer(VanillaTypes.ITEM_STACK, new BlockStateRenderer(pairs)); +// +// // Sets up output slots. +// Object outputIngredient; +// if (recipeResult.block() instanceof LiquidBlock liquidBlock) { +// outputIngredient = this.fluidHelper.create(liquidBlock.getFluid(), 1000); +// } else { +// outputIngredient = this.setupIngredient(recipeResult); +// } +// builder.addSlot(RecipeIngredientRole.OUTPUT, 60, 6).addIngredientsUnsafe(List.of(outputIngredient)) +// .setCustomRenderer(Services.PLATFORM.getFluidHelper().getFluidIngredientType(), new FluidStateRenderer(Services.PLATFORM.getFluidHelper())).setCustomRenderer(VanillaTypes.ITEM_STACK, new BlockStateRenderer(recipeResult)); +// } +// } +// +// /** +// * Warning for "deprecation" is suppressed because the non-sensitive version of {@link net.minecraft.world.level.block.Block#getCloneItemStack(BlockGetter, BlockPos, BlockState)} is needed in this context. +// */ +// @SuppressWarnings("deprecation") +// private ItemStack setupIngredient(BlockPropertyPair recipeResult) { +// ItemStack stack = ItemStack.EMPTY; +// if (Minecraft.getInstance().level != null) { +// BlockState resultState = recipeResult.block().defaultBlockState(); +// for (Map.Entry, Comparable> propertyEntry : recipeResult.properties().entrySet()) { +// resultState = BlockStateRecipeUtil.setHelper(propertyEntry, resultState); +// } +// stack = recipeResult.block().getCloneItemStack(Minecraft.getInstance().level, BlockPos.ZERO, resultState); +// } +// return stack.isEmpty() ? new ItemStack(Blocks.STONE) : stack; +// } +// +// @Override +// public void draw(T recipe, IRecipeSlotsView recipeSlotsView, GuiGraphics guiGraphics, double mouseX, double mouseY) { } +// +// protected void populateAdditionalInformation(T recipe, List tooltip) { } +//} diff --git a/src/main/java/com/aetherteam/nitrogen/integration/jei/categories/fuel/AbstractFuelCategory.java b/src/main/java/com/aetherteam/nitrogen/integration/jei/categories/fuel/AbstractFuelCategory.java index d2a1ce5..61b8cd8 100644 --- a/src/main/java/com/aetherteam/nitrogen/integration/jei/categories/fuel/AbstractFuelCategory.java +++ b/src/main/java/com/aetherteam/nitrogen/integration/jei/categories/fuel/AbstractFuelCategory.java @@ -1,86 +1,86 @@ package com.aetherteam.nitrogen.integration.jei.categories.fuel; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; -import com.google.common.cache.LoadingCache; -import com.mojang.blaze3d.vertex.PoseStack; -import mezz.jei.api.gui.builder.IRecipeLayoutBuilder; -import mezz.jei.api.gui.drawable.IDrawable; -import mezz.jei.api.gui.drawable.IDrawableAnimated; -import mezz.jei.api.gui.ingredient.IRecipeSlotsView; -import mezz.jei.api.helpers.IGuiHelper; -import mezz.jei.api.recipe.IFocusGroup; -import mezz.jei.api.recipe.RecipeIngredientRole; -import mezz.jei.api.recipe.category.IRecipeCategory; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Font; -import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; - -import java.util.Comparator; -import java.util.List; - -/** - * An abstract class for JEI fuel recipe categories. - */ -public abstract class AbstractFuelCategory implements IRecipeCategory { - private final IDrawable background; - private final IDrawable icon; - private final LoadingCache cachedFuelIndicator; - - public AbstractFuelCategory(IGuiHelper helper, List craftingStations) { - String longestString = craftingStations.stream().max(Comparator.comparingInt(String::length)).get(); - Component longestStationName = Component.literal(longestString); - - Font fontRenderer = Minecraft.getInstance().font; - Component maxBurnTimeText = createBurnTimeText(10000, longestStationName); - int maxStringWidth = fontRenderer.width(maxBurnTimeText.getString()); - int backgroundHeight = 34; - int textPadding = 20; - - this.background = helper.drawableBuilder(this.getTexture(), 55, 36, 18, backgroundHeight).addPadding(0, 0, 0, textPadding + maxStringWidth).build(); - this.icon = helper.createDrawable(this.getTexture(), 176, 0, 14, 13); - - this.cachedFuelIndicator = CacheBuilder.newBuilder().maximumSize(25) - .build(new CacheLoader<>() { - @Override - public IDrawableAnimated load(Integer burnTime) { - return helper.drawableBuilder(AbstractFuelCategory.this.getTexture(), 176, 0, 14, 13).buildAnimated(burnTime, IDrawableAnimated.StartDirection.TOP, true); - } - }); - } - - @Override - public IDrawable getBackground() { - return this.background; - } - - @Override - public IDrawable getIcon() { - return this.icon; - } - - public abstract ResourceLocation getTexture(); - - @Override - public void setRecipe(IRecipeLayoutBuilder builder, FuelRecipe recipe, IFocusGroup focuses) { - builder.addSlot(RecipeIngredientRole.INPUT, 1, 17).addItemStacks(recipe.getInput()); - } - - @Override - public void draw(FuelRecipe recipe, IRecipeSlotsView recipeSlotsView, GuiGraphics guiGraphics, double mouseX, double mouseY) { - int burnTime = recipe.getBurnTime(); - IDrawableAnimated fuelIndicator = this.cachedFuelIndicator.getUnchecked(burnTime); - fuelIndicator.draw(guiGraphics, 1, 0); - - Font font = Minecraft.getInstance().font; - Component burnTimeText = createBurnTimeText(recipe.getBurnTime(), recipe.getUsage().getName()); - int stringWidth = font.width(burnTimeText); - guiGraphics.drawString(font, burnTimeText, this.background.getWidth() - stringWidth, 14, 0xFF808080, false); - } - - private static Component createBurnTimeText(int burnTime, Component usage) { - return Component.translatable("gui.jei.category.smelting.time.seconds", burnTime / 20).append(" (").append(usage).append(")"); - } -} +//import com.google.common.cache.CacheBuilder; +//import com.google.common.cache.CacheLoader; +//import com.google.common.cache.LoadingCache; +//import com.mojang.blaze3d.vertex.PoseStack; +//import mezz.jei.api.gui.builder.IRecipeLayoutBuilder; +//import mezz.jei.api.gui.drawable.IDrawable; +//import mezz.jei.api.gui.drawable.IDrawableAnimated; +//import mezz.jei.api.gui.ingredient.IRecipeSlotsView; +//import mezz.jei.api.helpers.IGuiHelper; +//import mezz.jei.api.recipe.IFocusGroup; +//import mezz.jei.api.recipe.RecipeIngredientRole; +//import mezz.jei.api.recipe.category.IRecipeCategory; +//import net.minecraft.client.Minecraft; +//import net.minecraft.client.gui.Font; +//import net.minecraft.client.gui.GuiGraphics; +//import net.minecraft.network.chat.Component; +//import net.minecraft.resources.ResourceLocation; +// +//import java.util.Comparator; +//import java.util.List; +// +///** +// * An abstract class for JEI fuel recipe categories. +// */ +//public abstract class AbstractFuelCategory implements IRecipeCategory { +// private final IDrawable background; +// private final IDrawable icon; +// private final LoadingCache cachedFuelIndicator; +// +// public AbstractFuelCategory(IGuiHelper helper, List craftingStations) { +// String longestString = craftingStations.stream().max(Comparator.comparingInt(String::length)).get(); +// Component longestStationName = Component.literal(longestString); +// +// Font fontRenderer = Minecraft.getInstance().font; +// Component maxBurnTimeText = createBurnTimeText(10000, longestStationName); +// int maxStringWidth = fontRenderer.width(maxBurnTimeText.getString()); +// int backgroundHeight = 34; +// int textPadding = 20; +// +// this.background = helper.drawableBuilder(this.getTexture(), 55, 36, 18, backgroundHeight).addPadding(0, 0, 0, textPadding + maxStringWidth).build(); +// this.icon = helper.createDrawable(this.getTexture(), 176, 0, 14, 13); +// +// this.cachedFuelIndicator = CacheBuilder.newBuilder().maximumSize(25) +// .build(new CacheLoader<>() { +// @Override +// public IDrawableAnimated load(Integer burnTime) { +// return helper.drawableBuilder(AbstractFuelCategory.this.getTexture(), 176, 0, 14, 13).buildAnimated(burnTime, IDrawableAnimated.StartDirection.TOP, true); +// } +// }); +// } +// +// @Override +// public IDrawable getBackground() { +// return this.background; +// } +// +// @Override +// public IDrawable getIcon() { +// return this.icon; +// } +// +// public abstract ResourceLocation getTexture(); +// +// @Override +// public void setRecipe(IRecipeLayoutBuilder builder, FuelRecipe recipe, IFocusGroup focuses) { +// builder.addSlot(RecipeIngredientRole.INPUT, 1, 17).addItemStacks(recipe.getInput()); +// } +// +// @Override +// public void draw(FuelRecipe recipe, IRecipeSlotsView recipeSlotsView, GuiGraphics guiGraphics, double mouseX, double mouseY) { +// int burnTime = recipe.getBurnTime(); +// IDrawableAnimated fuelIndicator = this.cachedFuelIndicator.getUnchecked(burnTime); +// fuelIndicator.draw(guiGraphics, 1, 0); +// +// Font font = Minecraft.getInstance().font; +// Component burnTimeText = createBurnTimeText(recipe.getBurnTime(), recipe.getUsage().getName()); +// int stringWidth = font.width(burnTimeText); +// guiGraphics.drawString(font, burnTimeText, this.background.getWidth() - stringWidth, 14, 0xFF808080, false); +// } +// +// private static Component createBurnTimeText(int burnTime, Component usage) { +// return Component.translatable("gui.jei.category.smelting.time.seconds", burnTime / 20).append(" (").append(usage).append(")"); +// } +//} diff --git a/src/main/java/com/aetherteam/nitrogen/integration/jei/categories/fuel/FuelRecipe.java b/src/main/java/com/aetherteam/nitrogen/integration/jei/categories/fuel/FuelRecipe.java index 22721d9..10e00c1 100644 --- a/src/main/java/com/aetherteam/nitrogen/integration/jei/categories/fuel/FuelRecipe.java +++ b/src/main/java/com/aetherteam/nitrogen/integration/jei/categories/fuel/FuelRecipe.java @@ -1,33 +1,33 @@ package com.aetherteam.nitrogen.integration.jei.categories.fuel; -import com.google.common.base.Preconditions; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.block.Block; - -import java.util.Collection; -import java.util.List; - -public class FuelRecipe { - private final List inputs; - private final int burnTime; - private final Block usage; - - public FuelRecipe(Collection input, int burnTime, Block usage) { - Preconditions.checkArgument(burnTime > 0, "burn time must be greater than 0"); - this.inputs = List.copyOf(input); - this.burnTime = burnTime; - this.usage = usage; - } - - public List getInput() { - return inputs; - } - - public int getBurnTime() { - return burnTime; - } - - public Block getUsage() { - return usage; - } -} +//import com.google.common.base.Preconditions; +//import net.minecraft.world.item.ItemStack; +//import net.minecraft.world.level.block.Block; +// +//import java.util.Collection; +//import java.util.List; +// +//public class FuelRecipe { +// private final List inputs; +// private final int burnTime; +// private final Block usage; +// +// public FuelRecipe(Collection input, int burnTime, Block usage) { +// Preconditions.checkArgument(burnTime > 0, "burn time must be greater than 0"); +// this.inputs = List.copyOf(input); +// this.burnTime = burnTime; +// this.usage = usage; +// } +// +// public List getInput() { +// return inputs; +// } +// +// public int getBurnTime() { +// return burnTime; +// } +// +// public Block getUsage() { +// return usage; +// } +//} diff --git a/src/main/java/com/aetherteam/nitrogen/integration/rei/REIUtils.java b/src/main/java/com/aetherteam/nitrogen/integration/rei/REIUtils.java index c81cb16..3e4806c 100644 --- a/src/main/java/com/aetherteam/nitrogen/integration/rei/REIUtils.java +++ b/src/main/java/com/aetherteam/nitrogen/integration/rei/REIUtils.java @@ -13,7 +13,7 @@ import net.minecraft.world.level.block.LiquidBlock; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.properties.Property; -import net.minecraftforge.fluids.FluidType; +import net.neoforged.neoforge.fluids.FluidType; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/com/aetherteam/nitrogen/item/block/EntityBlockItem.java b/src/main/java/com/aetherteam/nitrogen/item/block/EntityBlockItem.java index 98b63db..3ce991d 100644 --- a/src/main/java/com/aetherteam/nitrogen/item/block/EntityBlockItem.java +++ b/src/main/java/com/aetherteam/nitrogen/item/block/EntityBlockItem.java @@ -5,9 +5,9 @@ import net.minecraft.world.item.BlockItem; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraftforge.client.extensions.common.IClientItemExtensions; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.common.util.NonNullSupplier; +import net.neoforged.neoforge.client.extensions.common.IClientItemExtensions; +import net.neoforged.neoforge.common.util.LazyOptional; +import net.neoforged.neoforge.common.util.NonNullSupplier; import java.util.function.Consumer; diff --git a/src/main/java/com/aetherteam/nitrogen/network/BasePacket.java b/src/main/java/com/aetherteam/nitrogen/network/BasePacket.java index 02753dd..a88b808 100644 --- a/src/main/java/com/aetherteam/nitrogen/network/BasePacket.java +++ b/src/main/java/com/aetherteam/nitrogen/network/BasePacket.java @@ -2,15 +2,15 @@ import net.minecraft.network.FriendlyByteBuf; import net.minecraft.world.entity.player.Player; -import net.minecraftforge.network.NetworkEvent; +import net.neoforged.neoforge.network.NetworkEvent; import java.util.function.Supplier; public interface BasePacket { void encode(FriendlyByteBuf buf); - default boolean handle(Supplier context) { - context.get().enqueueWork(() -> execute(context.get().getSender())); + default boolean handle(NetworkEvent.Context context) { + context.enqueueWork(() -> execute(context.getSender())); return true; } diff --git a/src/main/java/com/aetherteam/nitrogen/network/NitrogenPacketHandler.java b/src/main/java/com/aetherteam/nitrogen/network/NitrogenPacketHandler.java index fc8b733..715fbab 100644 --- a/src/main/java/com/aetherteam/nitrogen/network/NitrogenPacketHandler.java +++ b/src/main/java/com/aetherteam/nitrogen/network/NitrogenPacketHandler.java @@ -5,8 +5,9 @@ import com.aetherteam.nitrogen.network.packet.serverbound.TriggerUpdateInfoPacket; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; -import net.minecraftforge.network.NetworkRegistry; -import net.minecraftforge.network.simple.SimpleChannel; +import net.neoforged.neoforge.network.NetworkRegistry; +import net.neoforged.neoforge.network.simple.MessageFunctions; +import net.neoforged.neoforge.network.simple.SimpleChannel; import java.util.function.Function; @@ -27,7 +28,7 @@ public static synchronized void register() { register(TriggerUpdateInfoPacket.class, TriggerUpdateInfoPacket::decode); } - private static void register(final Class packet, Function decoder) { + private static void register(final Class packet, MessageFunctions.MessageDecoder decoder) { INSTANCE.messageBuilder(packet, index++).encoder(BasePacket::encode).decoder(decoder).consumerMainThread(BasePacket::handle).add(); } } diff --git a/src/main/java/com/aetherteam/nitrogen/network/PacketRelay.java b/src/main/java/com/aetherteam/nitrogen/network/PacketRelay.java index 547059b..c801005 100644 --- a/src/main/java/com/aetherteam/nitrogen/network/PacketRelay.java +++ b/src/main/java/com/aetherteam/nitrogen/network/PacketRelay.java @@ -3,8 +3,8 @@ import net.minecraft.resources.ResourceKey; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.level.Level; -import net.minecraftforge.network.PacketDistributor; -import net.minecraftforge.network.simple.SimpleChannel; +import net.neoforged.neoforge.network.PacketDistributor; +import net.neoforged.neoforge.network.simple.SimpleChannel; public class PacketRelay { public static void sendToPlayer(SimpleChannel handler, MSG message, ServerPlayer player) { diff --git a/src/main/java/com/aetherteam/nitrogen/network/packet/SyncEntityPacket.java b/src/main/java/com/aetherteam/nitrogen/network/packet/SyncEntityPacket.java index 79998cd..c90f98c 100644 --- a/src/main/java/com/aetherteam/nitrogen/network/packet/SyncEntityPacket.java +++ b/src/main/java/com/aetherteam/nitrogen/network/packet/SyncEntityPacket.java @@ -6,7 +6,7 @@ import net.minecraft.network.FriendlyByteBuf; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; -import net.minecraftforge.common.util.LazyOptional; +import net.neoforged.neoforge.common.util.LazyOptional; import org.apache.commons.lang3.tuple.Triple; import oshi.util.tuples.Quartet; diff --git a/src/main/java/com/aetherteam/nitrogen/network/packet/SyncLevelPacket.java b/src/main/java/com/aetherteam/nitrogen/network/packet/SyncLevelPacket.java index d6dbdf1..8a570de 100644 --- a/src/main/java/com/aetherteam/nitrogen/network/packet/SyncLevelPacket.java +++ b/src/main/java/com/aetherteam/nitrogen/network/packet/SyncLevelPacket.java @@ -6,7 +6,7 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.Level; -import net.minecraftforge.common.util.LazyOptional; +import net.neoforged.neoforge.common.util.LazyOptional; import org.apache.commons.lang3.tuple.Triple; /** diff --git a/src/main/java/com/aetherteam/nitrogen/recipe/BlockStateIngredient.java b/src/main/java/com/aetherteam/nitrogen/recipe/BlockStateIngredient.java index bb79da4..b8ce6b3 100644 --- a/src/main/java/com/aetherteam/nitrogen/recipe/BlockStateIngredient.java +++ b/src/main/java/com/aetherteam/nitrogen/recipe/BlockStateIngredient.java @@ -1,6 +1,8 @@ package com.aetherteam.nitrogen.recipe; import com.google.gson.*; +import net.minecraft.core.HolderSet; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.Registries; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; @@ -9,12 +11,13 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.properties.Property; -import net.minecraftforge.registries.ForgeRegistries; -import net.minecraftforge.registries.tags.ITagManager; +import net.neoforged.neoforge.common.NeoForgeMod; +import net.neoforged.neoforge.common.crafting.IngredientType; import javax.annotation.Nullable; import java.util.*; import java.util.function.Predicate; +import java.util.function.Supplier; import java.util.stream.Stream; import java.util.stream.StreamSupport; @@ -22,14 +25,33 @@ * [CODE COPY] - {@link net.minecraft.world.item.crafting.Ingredient}.

* Modified to be based on a {@link Predicate}<{@link BlockState}>. */ -public class BlockStateIngredient implements Predicate { +public class BlockStateIngredient implements Predicate { //todo: codecs public static final BlockStateIngredient EMPTY = new BlockStateIngredient(Stream.empty()); private final BlockStateIngredient.Value[] values; @Nullable private BlockPropertyPair[] pairs; + private final Supplier> type; - protected BlockStateIngredient(Stream values) { - this.values = values.toArray(Value[]::new); + public BlockStateIngredient(Stream values) { + this(values, NeoForgeMod.VANILLA_INGREDIENT_TYPE); + } + + public BlockStateIngredient(BlockStateIngredient.Value[] values) { + this(values, NeoForgeMod.VANILLA_INGREDIENT_TYPE); + } + + public BlockStateIngredient(Stream values, Supplier> type) { + this.values = values.toArray(BlockStateIngredient.Value[]::new); + this.type = type; + } + + public BlockStateIngredient(BlockStateIngredient.Value[] values, Supplier> type) { + this.values = values; + this.type = type; + } + + public IngredientType getType() { + return type.get(); } private void dissolve() { @@ -184,7 +206,7 @@ public Collection getPairs() { @Override public JsonObject serialize() { JsonObject jsonObject = new JsonObject(); - ResourceLocation blockLocation = ForgeRegistries.BLOCKS.getKey(this.block); + ResourceLocation blockLocation = BuiltInRegistries.BLOCK.getKey(this.block); if (blockLocation == null) { throw new JsonParseException("Block for ingredient StateValue serialization shouldn't be null"); } else { @@ -217,7 +239,7 @@ public Collection getPairs() { @Override public JsonObject serialize() { JsonObject jsonObject = new JsonObject(); - ResourceLocation blockLocation = ForgeRegistries.BLOCKS.getKey(this.block); + ResourceLocation blockLocation = BuiltInRegistries.BLOCK.getKey(this.block); if (blockLocation == null) { throw new JsonParseException("Block for ingredient StateValue serialization shouldn't be null"); } else { @@ -237,10 +259,10 @@ public TagValue(TagKey tag) { @Override public Collection getPairs() { List list = new ArrayList<>(); - ITagManager tags = ForgeRegistries.BLOCKS.tags(); - if (tags != null) { - tags.getTag(this.tag).stream().forEach((block) -> list.add(BlockPropertyPair.of(block, Map.of()))); - } + + Optional> tags = BuiltInRegistries.BLOCK.getTag(this.tag); + tags.ifPresent(holders -> holders.stream().forEach((block) -> list.add(BlockPropertyPair.of(block.value(), Map.of())))); + return list; } diff --git a/src/main/java/com/aetherteam/nitrogen/recipe/BlockStateRecipeUtil.java b/src/main/java/com/aetherteam/nitrogen/recipe/BlockStateRecipeUtil.java index b23fac0..57f2d33 100644 --- a/src/main/java/com/aetherteam/nitrogen/recipe/BlockStateRecipeUtil.java +++ b/src/main/java/com/aetherteam/nitrogen/recipe/BlockStateRecipeUtil.java @@ -5,6 +5,7 @@ import net.minecraft.commands.CommandFunction; import net.minecraft.commands.CommandSourceStack; import net.minecraft.core.BlockPos; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.Registries; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.FriendlyByteBuf; @@ -22,7 +23,6 @@ import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.Property; import net.minecraft.world.phys.Vec3; -import net.minecraftforge.registries.ForgeRegistries; import org.apache.commons.lang3.tuple.Pair; import javax.annotation.Nullable; @@ -56,7 +56,7 @@ public static void executeFunction(Level level, BlockPos pos, @Nullable CommandF * @param pair The {@link BlockPropertyPair}. */ public static void writePair(FriendlyByteBuf buffer, BlockPropertyPair pair) { - ResourceLocation blockLocation = ForgeRegistries.BLOCKS.getKey(pair.block()); + ResourceLocation blockLocation = BuiltInRegistries.BLOCK.getKey(pair.block()); if ((pair.block().defaultBlockState().isAir() && pair.properties().isEmpty()) || blockLocation == null) { buffer.writeBoolean(false); } else { @@ -113,7 +113,7 @@ public static BlockPropertyPair readPair(FriendlyByteBuf buffer) { } else { String blockString = buffer.readUtf(); ResourceLocation blockLocation = new ResourceLocation(blockString); - Block block = ForgeRegistries.BLOCKS.getValue(blockLocation); + Block block = BuiltInRegistries.BLOCK.get(blockLocation); if (block == null) { throw new JsonSyntaxException("Unknown block '" + blockLocation + "'"); } @@ -231,7 +231,7 @@ public static BlockPropertyPair pairFromJson(JsonObject json) { public static Block blockFromJson(JsonObject json) { String blockName = GsonHelper.getAsString(json, "block"); ResourceLocation blockLocation = new ResourceLocation(blockName); - Block block = ForgeRegistries.BLOCKS.getValue(blockLocation); + Block block = BuiltInRegistries.BLOCK.get(blockLocation); if (block == null) { throw new JsonSyntaxException("Unknown block '" + blockLocation + "'"); } diff --git a/src/main/java/com/aetherteam/nitrogen/recipe/builder/BlockStateRecipeBuilder.java b/src/main/java/com/aetherteam/nitrogen/recipe/builder/BlockStateRecipeBuilder.java index 3f592ec..558f575 100644 --- a/src/main/java/com/aetherteam/nitrogen/recipe/builder/BlockStateRecipeBuilder.java +++ b/src/main/java/com/aetherteam/nitrogen/recipe/builder/BlockStateRecipeBuilder.java @@ -5,9 +5,11 @@ import com.aetherteam.nitrogen.recipe.recipes.AbstractBlockStateRecipe; import com.aetherteam.nitrogen.recipe.serializer.BlockStateRecipeSerializer; import com.google.gson.JsonObject; -import net.minecraft.advancements.CriterionTriggerInstance; +import net.minecraft.advancements.AdvancementHolder; +import net.minecraft.advancements.Criterion; import net.minecraft.data.recipes.FinishedRecipe; import net.minecraft.data.recipes.RecipeBuilder; +import net.minecraft.data.recipes.RecipeOutput; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.Item; import net.minecraft.world.item.Items; @@ -17,7 +19,6 @@ import javax.annotation.Nullable; import java.util.Map; -import java.util.function.Consumer; public class BlockStateRecipeBuilder implements RecipeBuilder { private final BlockPropertyPair result; @@ -72,13 +73,13 @@ public Item getResult() { } @Override - public RecipeBuilder unlockedBy(String criterionName, CriterionTriggerInstance criterionTrigger) { + public RecipeBuilder unlockedBy(String criterionName, Criterion criterionTrigger) { return this; } @Override - public void save(Consumer finishedRecipeConsumer, ResourceLocation id) { - finishedRecipeConsumer.accept(new BlockStateRecipeBuilder.Result(id, this.ingredient, this.result, this.serializer, this.function)); + public void save(RecipeOutput output, ResourceLocation id) { + output.accept(new BlockStateRecipeBuilder.Result(id, this.ingredient, this.result, this.serializer, this.function)); } public static class Result implements FinishedRecipe { @@ -115,24 +116,18 @@ public void serializeRecipeData(JsonObject json) { } @Override - public RecipeSerializer getType() { + public RecipeSerializer type() { return this.serializer; } @Override - public ResourceLocation getId() { + public ResourceLocation id() { return this.id; } @Nullable @Override - public JsonObject serializeAdvancement() { - return null; - } - - @Nullable - @Override - public ResourceLocation getAdvancementId() { + public AdvancementHolder advancement() { return null; } } diff --git a/src/main/java/com/aetherteam/nitrogen/recipe/recipes/AbstractBlockStateRecipe.java b/src/main/java/com/aetherteam/nitrogen/recipe/recipes/AbstractBlockStateRecipe.java index 85a712e..ac3ad04 100644 --- a/src/main/java/com/aetherteam/nitrogen/recipe/recipes/AbstractBlockStateRecipe.java +++ b/src/main/java/com/aetherteam/nitrogen/recipe/recipes/AbstractBlockStateRecipe.java @@ -5,7 +5,6 @@ import com.aetherteam.nitrogen.recipe.BlockStateRecipeUtil; import net.minecraft.commands.CommandFunction; import net.minecraft.core.BlockPos; -import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.crafting.RecipeType; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; @@ -16,15 +15,13 @@ public abstract class AbstractBlockStateRecipe implements BlockStateRecipe { protected final RecipeType type; - protected final ResourceLocation id; protected final BlockStateIngredient ingredient; protected final BlockPropertyPair result; @Nullable protected final CommandFunction.CacheableFunction function; - public AbstractBlockStateRecipe(RecipeType type, ResourceLocation id, BlockStateIngredient ingredient, BlockPropertyPair result, @Nullable CommandFunction.CacheableFunction function) { + public AbstractBlockStateRecipe(RecipeType type, BlockStateIngredient ingredient, BlockPropertyPair result, @Nullable CommandFunction.CacheableFunction function) { this.type = type; - this.id = id; this.ingredient = ingredient; this.result = result; this.function = function; @@ -71,11 +68,6 @@ public RecipeType getType() { return this.type; } - @Override - public ResourceLocation getId() { - return this.id; - } - @Override public BlockStateIngredient getIngredient() { return this.ingredient; diff --git a/src/main/java/com/aetherteam/nitrogen/recipe/serializer/BlockStateRecipeSerializer.java b/src/main/java/com/aetherteam/nitrogen/recipe/serializer/BlockStateRecipeSerializer.java index 9a85a66..cf01502 100644 --- a/src/main/java/com/aetherteam/nitrogen/recipe/serializer/BlockStateRecipeSerializer.java +++ b/src/main/java/com/aetherteam/nitrogen/recipe/serializer/BlockStateRecipeSerializer.java @@ -7,6 +7,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonSyntaxException; +import com.mojang.serialization.Codec; import net.minecraft.commands.CommandFunction; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; @@ -22,7 +23,6 @@ public BlockStateRecipeSerializer(BlockStateRecipeSerializer.CookieBaker fact this.factory = factory; } - @Override public T fromJson(ResourceLocation id, JsonObject json) { if (!json.has("ingredient")) throw new JsonSyntaxException("Missing ingredient, expected to find an object or array"); JsonElement jsonElement = GsonHelper.isArrayNode(json, "ingredient") ? GsonHelper.getAsJsonArray(json, "ingredient") : GsonHelper.getAsJsonObject(json, "ingredient"); @@ -47,7 +47,6 @@ public T fromJson(ResourceLocation id, JsonObject json) { } @Nullable - @Override public T fromNetwork(ResourceLocation id, FriendlyByteBuf buffer) { BlockStateIngredient ingredient = BlockStateIngredient.fromNetwork(buffer); BlockPropertyPair result = BlockStateRecipeUtil.readPair(buffer); @@ -55,6 +54,16 @@ public T fromNetwork(ResourceLocation id, FriendlyByteBuf buffer) { return this.factory.create(id, ingredient, result, function); } + @Override + public Codec codec() { + return null; + } + + @Override + public T fromNetwork(FriendlyByteBuf pBuffer) { + return null; + } + @Override public void toNetwork(FriendlyByteBuf buffer, T recipe) { recipe.getIngredient().toNetwork(buffer); diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index e3b55b3..f932f85 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -1,5 +1,5 @@ modLoader = "javafml" -loaderVersion = "[47,)" +loaderVersion = "[1,)" license = "Assets: All Rights Reserved; Code: LGPL-3.0" issueTrackerURL="https://github.com/The-Aether-Team/Nitrogen/issues" @@ -15,14 +15,17 @@ description = ''' A library used for the Aether series of mods.''' [[dependencies.nitrogen_internals]] - modId = "forge" - mandatory = true - versionRange = "[47.1.0,)" - ordering = "NONE" - side = "BOTH" + modId="neoforge" + mandatory=true + versionRange="[20.2.0,)" + ordering="NONE" + side="BOTH" [[dependencies.nitrogen_internals]] - modId = "minecraft" - mandatory = true - versionRange = "[1.20.1]" - ordering = "NONE" - side = "BOTH" + modId="minecraft" + mandatory=true + versionRange="[1.20.2,1.20.3)" + ordering="NONE" + side="BOTH" + +[[mixins]] + config="nitrogen_internals.mixins.json" \ No newline at end of file