diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e7c48a11..024329af 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,6 +49,8 @@ jobs: SIGN_STOREPASS: ${{ secrets.SIGN_STOREPASS }} MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }} MAVEN_KEY: ${{ secrets.MAVEN_KEY }} + GITHUB_USER: ${{ github.actor }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: 'Test' env: COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }} diff --git a/.gitignore b/.gitignore index 2a3fa29c..ca42da40 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ doc/info.txt /build /run +/runs # Ignore project specific files .classpath @@ -17,6 +18,7 @@ repo/* *.iws out/* keystore.jks +.idea # Ignore mac-specific file(s) .DS_Store diff --git a/build.gradle b/build.gradle index ea1f845b..63f3c850 100644 --- a/build.gradle +++ b/build.gradle @@ -1,15 +1,14 @@ plugins { - id 'net.minecraftforge.gradle' version '[6.0,6.2)' - id 'com.matthewprenger.cursegradle' version '1.4.0' + id 'net.neoforged.gradle.userdev' version '7.0.97' + id 'net.darkhax.curseforgegradle' version '1.0.8' id 'com.diffplug.spotless' version '5.14.3' id 'com.modrinth.minotaur' version '2.+' } -apply plugin: 'net.minecraftforge.gradle' apply plugin: 'idea' apply plugin: 'maven-publish' -import net.minecraftforge.gradle.common.tasks.SignJar +import net.neoforged.gradle.common.tasks.PotentiallySignJar // Determine build number String build_number = "DEV" // this will be referenced as simply build_number from now on. @@ -26,7 +25,10 @@ logger.lifecycle "BUILDING VERSION: " + build_number // Set mod details version = project.mod_version group = "org.cyclops.colossalchests" -archivesBaseName = "ColossalChests" +archivesBaseName = "ColossalChests-${project.minecraft_version}-neoforge" +base { + archivesName = archivesBaseName +} // Set Java details java.toolchain.languageVersion = JavaLanguageVersion.of(17) @@ -56,6 +58,7 @@ sourceSets { runtimeClasspath += sourceSets.api.output } } +sourceSets.main.resources { srcDir 'src/generated/resources' } configurations { apiImplementation.extendsFrom(implementation) @@ -70,26 +73,26 @@ repositories { name "Cyclops Repo" url "https://maven.pkg.github.com/CyclopsMC/packages" credentials { - username = project.findProperty("gpr.user") ?: System.getenv("MAVEN_USERNAME") - password = project.findProperty("gpr.key") ?: System.getenv("MAVEN_KEY") + username = project.findProperty("gpr.user") ?: System.getenv("MAVEN_USERNAME") ?: System.getenv("GITHUB_USER") + password = project.findProperty("gpr.key") ?: System.getenv("MAVEN_KEY") ?: System.getenv("GITHUB_TOKEN") } } } dependencies { - minecraft "net.minecraftforge:forge:${project.minecraft_version}-${project.forge_version}" + implementation "net.neoforged:neoforge:${project.neoforge_version}" // Add something like 'cyclopscore_version_local=0.1.0-DEV' to your secrets.properties if you want to use a custom local CyclopsCore version. if(secrets.cyclopscore_version_local) { - implementation "org.cyclops.cyclopscore:cyclopscore:${project.minecraft_version}-${secrets.cyclopscore_version_local}:deobf" + implementation "org.cyclops.cyclopscore:cyclopscore-${project.minecraft_version}-neoforge:${secrets.cyclopscore_version_local}:deobf" } else { - implementation "org.cyclops.cyclopscore:cyclopscore:${project.minecraft_version}-${project.cyclopscore_version}:deobf" + implementation "org.cyclops.cyclopscore:cyclopscore-${project.minecraft_version}-neoforge:${project.cyclopscore_version}:deobf" } if(secrets.commoncapabilities_version_local) { - implementation "org.cyclops.commoncapabilities:commoncapabilities:${secrets.commoncapabilities_version_local}:deobf" + implementation "org.cyclops.commoncapabilities:commoncapabilities-${project.minecraft_version}-neoforge:${secrets.commoncapabilities_version_local}:deobf" } else { - implementation fg.deobf("org.cyclops.commoncapabilities:commoncapabilities:${project.commoncapabilities_version}") { // https://dl.bintray.com/cyclopsmc/dev/org/cyclops/commoncapabilities/CommonCapabilities/ + implementation("org.cyclops.commoncapabilities:commoncapabilities-${project.minecraft_version}-neoforge:${project.commoncapabilities_version}:deobf") { // https://dl.bintray.com/cyclopsmc/dev/org/cyclops/commoncapabilities/CommonCapabilities/ exclude group: 'org.cyclops.cyclopscore', module: 'cyclopscore' } } @@ -102,43 +105,41 @@ dependencies { } minecraft { - mappings channel: "official", version: "${project.minecraft_version}" + accessTransformers { + file('src/main/resources/META-INF/accesstransformer.cfg') + } +} - accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') +runs { + configureEach { + systemProperty 'forge.logging.markers', 'REGISTRIES' + systemProperty 'forge.logging.console.level', 'debug' + systemProperty 'forge.logging.console.level', 'debug' + modSource project.sourceSets.main + } + + client { + systemProperty 'forge.enabledGameTestNamespaces', project.mod_id + } - runs { - client { - workingDirectory project.file('run') - //property 'forge.logging.markers', 'REGISTRIES,REGISTRYDUMP' - property 'forge.logging.console.level', 'debug' - mods { - colossalchests.sources((SourceSet[]) [sourceSets.main, sourceSets.api]) - } - } + server { + systemProperty 'forge.enabledGameTestNamespaces', project.mod_id + programArgument '--nogui' + } - server { - workingDirectory project.file('run') - property 'forge.logging.console.level', 'debug' - mods { - colossalchests.sources((SourceSet[]) [sourceSets.main, sourceSets.api]) - } - } + gameTestServer { + systemProperty 'forge.enabledGameTestNamespaces', project.mod_id + } - data { - workingDirectory project.file('run') - property 'forge.logging.console.level', 'debug' - args '--mod', 'colossalchests', '--all', '--output', file('src/generated/resources/') - mods { - colossalchests.sources((SourceSet[]) [sourceSets.main, sourceSets.api]) - } - } + data { + programArguments.addAll '--mod', project.mod_id, '--all', '--output', file('src/generated/resources/').getAbsolutePath(), '--existing', file('src/main/resources/').getAbsolutePath() } } if (build_number.equals("RELEASE")) - version = "${project.minecraft_version}-${project.mod_version}" + version = "${project.mod_version}" else - version = "${project.minecraft_version}-${project.mod_version}-${build_number}" + version = "${project.mod_version}-${build_number}" jar { manifest { @@ -154,7 +155,6 @@ jar { ]) } } -jar.finalizedBy('reobfJar') javadoc { source = [sourceSets.main.allJava] @@ -162,7 +162,9 @@ javadoc { options.addStringOption('Xdoclint:accessibility,html,reference,syntax', '-quiet') } -task signJar(type: SignJar, dependsOn: jar) { +task signJar(type: PotentiallySignJar, dependsOn: jar) { + dependsOn(tasks.jar) + onlyIf { System.getenv().SIGN_KEYSTORE } @@ -171,8 +173,8 @@ task signJar(type: SignJar, dependsOn: jar) { alias = System.getenv().SIGN_ALIAS storePass = System.getenv().SIGN_STOREPASS keyPass = System.getenv().SIGN_KEYPASS - inputFile = jar.archivePath - outputFile = jar.archivePath + input = jar.archivePath + output = jar.archivePath } build.dependsOn signJar @@ -219,32 +221,28 @@ artifacts { archives javadocJar } -curseforge { - if(secrets.curseforge_key) { - apiKey = secrets.curseforge_key +task publishCurseForge(type: net.darkhax.curseforgegradle.TaskPublishCurseForge) { + dependsOn(tasks.jar) + + if(secrets.hasProperty("curseforge_key") && secrets.hasProperty("changelog")) { + apiToken = secrets.curseforge_key } else if(System.getenv().GITHUB_ACTIONS && System.getenv().CURSEFORGE_KEY_SECRET) { - apiKey = System.getenv().CURSEFORGE_KEY_SECRET + apiToken = System.getenv().CURSEFORGE_KEY_SECRET + } else { + apiToken = "DUMMY" } - project { - id = "237875" // my project url is http://minecraft.curseforge.com/mc-mods/237875/ - releaseType = project.project.release_type - addGameVersion project.minecraft_version - mainArtifact(jar) { - relations { - requiredDependency 'cyclops-core' - } - } + def projectId = "237875" // my project url is http://minecraft.curseforge.com/mc-mods/237875/ - changelog = "" - if (new File("resources/changelog/${project.version}.txt").exists()) { - changelog = new File("resources/changelog/${project.version}.txt").text - } - - addArtifact deobfJar - addArtifact sourcesJar - addArtifact javadocJar + def mainFile = upload(projectId, jar) + mainFile.changelogType = "text" + if (new File("resources/changelog/${project.version}.txt").exists()) { + mainFile.changelog = file("resources/changelog/${project.version}.txt") } + mainFile.addGameVersion(project.minecraft_version) + mainFile.addModLoader("NeoForge") + + mainFile.addRequirement('cyclops-core') } modrinth { @@ -326,3 +324,7 @@ tasks.register('updateGitHooks', Copy) { into './.git/hooks' } compileJava.dependsOn updateGitHooks + +tasks.withType(JavaCompile).configureEach { + options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 7560cee7..91685152 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,11 +1,12 @@ +mod_id=colossalchests mod_version=1.8.4 -minecraft_version=1.20.1 -forge_version=47.0.1 -cyclopscore_version=1.18.4-340 +minecraft_version=1.20.4 +neoforge_version=20.4.160-beta +cyclopscore_version=1.19.0-421 release_type=release fingerprint=bd0353b3e8a2810d60dd584e256e364bc3bedd44 -commoncapabilities_version=1.20.1-2.9.0-98 +commoncapabilities_version=2.9.1-113 # Workaround for Spotless bug # https://github.com/diffplug/spotless/issues/834 diff --git a/settings.gradle b/settings.gradle index a30364e8..b359a59d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,10 +1,8 @@ pluginManagement { repositories { + mavenLocal() gradlePluginPortal() - maven { - name = 'MinecraftForge' - url = 'https://maven.minecraftforge.net/' - } + maven { url = 'https://maven.neoforged.net/releases' } } } diff --git a/src/main/java/org/cyclops/colossalchests/Advancements.java b/src/main/java/org/cyclops/colossalchests/Advancements.java deleted file mode 100644 index ede3e190..00000000 --- a/src/main/java/org/cyclops/colossalchests/Advancements.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.cyclops.colossalchests; - -import org.cyclops.colossalchests.advancement.criterion.ChestFormedTrigger; -import org.cyclops.cyclopscore.helper.AdvancementHelpers; - -/** - * Advancement-related logic. - * @author rubensworks - */ -public class Advancements { - - public static final ChestFormedTrigger CHEST_FORMED = AdvancementHelpers - .registerCriteriaTrigger(new ChestFormedTrigger()); - - public static void load() {} - -} diff --git a/src/main/java/org/cyclops/colossalchests/Capabilities.java b/src/main/java/org/cyclops/colossalchests/Capabilities.java deleted file mode 100644 index 6fd4b10f..00000000 --- a/src/main/java/org/cyclops/colossalchests/Capabilities.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.cyclops.colossalchests; - -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.common.capabilities.CapabilityManager; -import net.minecraftforge.common.capabilities.CapabilityToken; -import org.cyclops.commoncapabilities.api.capability.inventorystate.IInventoryState; -import org.cyclops.commoncapabilities.api.capability.itemhandler.ISlotlessItemHandler; - -/** - * Used capabilities for this mod. - * @author rubensworks - */ -public class Capabilities { - public static Capability INVENTORY_STATE = CapabilityManager.get(new CapabilityToken<>(){}); - public static Capability SLOTLESS_ITEMHANDLER = CapabilityManager.get(new CapabilityToken<>(){}); -} diff --git a/src/main/java/org/cyclops/colossalchests/ColossalChests.java b/src/main/java/org/cyclops/colossalchests/ColossalChests.java index e95b4f42..e974c452 100644 --- a/src/main/java/org/cyclops/colossalchests/ColossalChests.java +++ b/src/main/java/org/cyclops/colossalchests/ColossalChests.java @@ -2,11 +2,12 @@ import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.ItemStack; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; +import net.neoforged.bus.api.IEventBus; +import net.neoforged.fml.common.Mod; import org.apache.logging.log4j.Level; +import org.cyclops.colossalchests.advancement.criterion.ChestFormedTriggerConfig; import org.cyclops.colossalchests.block.ChestMaterial; import org.cyclops.colossalchests.block.ChestWallConfig; import org.cyclops.colossalchests.block.ColossalChestConfig; @@ -15,6 +16,7 @@ import org.cyclops.colossalchests.blockentity.BlockEntityColossalChestConfig; import org.cyclops.colossalchests.blockentity.BlockEntityInterfaceConfig; import org.cyclops.colossalchests.blockentity.BlockEntityUncolossalChestConfig; +import org.cyclops.colossalchests.condition.ConditionMetalVariantsSettingConfig; import org.cyclops.colossalchests.inventory.container.ContainerColossalChestConfig; import org.cyclops.colossalchests.inventory.container.ContainerUncolossalChestConfig; import org.cyclops.colossalchests.item.ItemUpgradeToolConfig; @@ -22,7 +24,6 @@ import org.cyclops.colossalchests.modcompat.IronChestModCompat; import org.cyclops.colossalchests.proxy.ClientProxy; import org.cyclops.colossalchests.proxy.CommonProxy; -import org.cyclops.colossalchests.recipe.condition.RecipeConditionMetalVariantsSettingConfig; import org.cyclops.cyclopscore.config.ConfigHandler; import org.cyclops.cyclopscore.init.ModBaseVersionable; import org.cyclops.cyclopscore.modcompat.ModCompatLoader; @@ -42,8 +43,8 @@ public class ColossalChests extends ModBaseVersionable { */ public static ColossalChests _instance; - public ColossalChests() { - super(Reference.MOD_ID, (instance) -> _instance = instance); + public ColossalChests(IEventBus modEventBus) { + super(Reference.MOD_ID, (instance) -> _instance = instance, modEventBus); } @Override @@ -52,12 +53,6 @@ protected void loadModCompats(ModCompatLoader modCompatLoader) { modCompatLoader.addModCompat(new CommonCapabilitiesModCompat()); } - @Override - protected void setup(FMLCommonSetupEvent event) { - super.setup(event); - Advancements.load(); - } - @Override @OnlyIn(Dist.CLIENT) protected IClientProxy constructClientProxy() { @@ -98,7 +93,9 @@ protected void onConfigsRegister(ConfigHandler configHandler) { configHandler.addConfigurable(new ContainerColossalChestConfig()); configHandler.addConfigurable(new ContainerUncolossalChestConfig()); - configHandler.addConfigurable(new RecipeConditionMetalVariantsSettingConfig()); + configHandler.addConfigurable(new ConditionMetalVariantsSettingConfig()); + + configHandler.addConfigurable(new ChestFormedTriggerConfig()); } /** diff --git a/src/main/java/org/cyclops/colossalchests/GeneralConfig.java b/src/main/java/org/cyclops/colossalchests/GeneralConfig.java index 1b655272..dc6b44bd 100644 --- a/src/main/java/org/cyclops/colossalchests/GeneralConfig.java +++ b/src/main/java/org/cyclops/colossalchests/GeneralConfig.java @@ -1,6 +1,6 @@ package org.cyclops.colossalchests; -import net.minecraftforge.fml.config.ModConfig; +import net.neoforged.fml.config.ModConfig; import org.cyclops.cyclopscore.config.ConfigurableProperty; import org.cyclops.cyclopscore.config.extendedconfig.DummyConfig; import org.cyclops.cyclopscore.init.ModBase; diff --git a/src/main/java/org/cyclops/colossalchests/RegistryEntries.java b/src/main/java/org/cyclops/colossalchests/RegistryEntries.java index bd45cb45..a1c1fa3c 100644 --- a/src/main/java/org/cyclops/colossalchests/RegistryEntries.java +++ b/src/main/java/org/cyclops/colossalchests/RegistryEntries.java @@ -1,10 +1,14 @@ package org.cyclops.colossalchests; +import net.minecraft.advancements.CriterionTrigger; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.inventory.MenuType; import net.minecraft.world.item.Item; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraftforge.registries.ObjectHolder; +import net.neoforged.neoforge.registries.DeferredHolder; +import org.cyclops.colossalchests.advancement.criterion.ChestFormedTrigger; import org.cyclops.colossalchests.blockentity.BlockEntityColossalChest; import org.cyclops.colossalchests.blockentity.BlockEntityInterface; import org.cyclops.colossalchests.blockentity.BlockEntityUncolossalChest; @@ -17,22 +21,17 @@ */ public class RegistryEntries { - @ObjectHolder(registryName = "item", value = "minecraft:chest") - public static final Item ITEM_CHEST = null; + public static final DeferredHolder ITEM_CHEST = DeferredHolder.create(Registries.ITEM, new ResourceLocation("minecraft:chest")); - @ObjectHolder(registryName = "block", value = "colossalchests:uncolossal_chest") - public static final Block BLOCK_UNCOLOSSAL_CHEST = null; + public static final DeferredHolder BLOCK_UNCOLOSSAL_CHEST = DeferredHolder.create(Registries.BLOCK, new ResourceLocation("colossalchests:uncolossal_chest")); - @ObjectHolder(registryName = "block_entity_type", value = "colossalchests:colossal_chest") - public static final BlockEntityType BLOCK_ENTITY_COLOSSAL_CHEST = null; - @ObjectHolder(registryName = "block_entity_type", value = "colossalchests:interface") - public static final BlockEntityType BLOCK_ENTITY_INTERFACE = null; - @ObjectHolder(registryName = "block_entity_type", value = "colossalchests:uncolossal_chest") - public static final BlockEntityType BLOCK_ENTITY_UNCOLOSSAL_CHEST = null; + public static final DeferredHolder, BlockEntityType> BLOCK_ENTITY_COLOSSAL_CHEST = DeferredHolder.create(Registries.BLOCK_ENTITY_TYPE, new ResourceLocation("colossalchests:colossal_chest")); + public static final DeferredHolder, BlockEntityType> BLOCK_ENTITY_INTERFACE = DeferredHolder.create(Registries.BLOCK_ENTITY_TYPE, new ResourceLocation("colossalchests:interface")); + public static final DeferredHolder, BlockEntityType> BLOCK_ENTITY_UNCOLOSSAL_CHEST = DeferredHolder.create(Registries.BLOCK_ENTITY_TYPE, new ResourceLocation("colossalchests:uncolossal_chest")); - @ObjectHolder(registryName = "menu", value = "colossalchests:colossal_chest") - public static final MenuType CONTAINER_COLOSSAL_CHEST = null; - @ObjectHolder(registryName = "menu", value = "colossalchests:uncolossal_chest") - public static final MenuType CONTAINER_UNCOLOSSAL_CHEST = null; + public static final DeferredHolder, MenuType> CONTAINER_COLOSSAL_CHEST = DeferredHolder.create(Registries.MENU, new ResourceLocation("colossalchests:colossal_chest")); + public static final DeferredHolder, MenuType> CONTAINER_UNCOLOSSAL_CHEST = DeferredHolder.create(Registries.MENU, new ResourceLocation("colossalchests:uncolossal_chest")); + + public static final DeferredHolder, ChestFormedTrigger> TRIGGER_CHEST_FORMED = DeferredHolder.create(Registries.TRIGGER_TYPE, new ResourceLocation("colossalchests:chest_formed")); } diff --git a/src/main/java/org/cyclops/colossalchests/advancement/criterion/ChestFormedTrigger.java b/src/main/java/org/cyclops/colossalchests/advancement/criterion/ChestFormedTrigger.java index faae68c7..018f733c 100644 --- a/src/main/java/org/cyclops/colossalchests/advancement/criterion/ChestFormedTrigger.java +++ b/src/main/java/org/cyclops/colossalchests/advancement/criterion/ChestFormedTrigger.java @@ -1,83 +1,51 @@ package org.cyclops.colossalchests.advancement.criterion; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonSyntaxException; -import net.minecraft.advancements.critereon.AbstractCriterionTriggerInstance; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import net.minecraft.advancements.critereon.ContextAwarePredicate; -import net.minecraft.advancements.critereon.DeserializationContext; +import net.minecraft.advancements.critereon.EntityPredicate; import net.minecraft.advancements.critereon.SimpleCriterionTrigger; -import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerPlayer; -import net.minecraft.util.GsonHelper; -import net.minecraftforge.common.MinecraftForge; +import net.minecraft.util.ExtraCodecs; import org.apache.commons.lang3.tuple.Pair; -import org.cyclops.colossalchests.Reference; import org.cyclops.colossalchests.block.ChestMaterial; import org.cyclops.cyclopscore.advancement.criterion.ICriterionInstanceTestable; -import javax.annotation.Nullable; -import java.util.Objects; -import java.util.stream.Collectors; +import java.util.Optional; /** * Triggers when a colossal chest is formed. * @author rubensworks */ public class ChestFormedTrigger extends SimpleCriterionTrigger { - private final ResourceLocation ID = new ResourceLocation(Reference.MOD_ID, "chest_formed"); - public ChestFormedTrigger() { - MinecraftForge.EVENT_BUS.register(this); - } + public static final Codec CODEC = RecordCodecBuilder.create( + p_311401_ -> p_311401_.group( + ExtraCodecs.strictOptionalField(EntityPredicate.ADVANCEMENT_CODEC, "player").forGetter(ChestFormedTrigger.Instance::player), + ExtraCodecs.strictOptionalField(ChestMaterial.CODEC, "material").forGetter(ChestFormedTrigger.Instance::material), + ExtraCodecs.strictOptionalField(Codec.INT, "minimumSize").forGetter(ChestFormedTrigger.Instance::minimumSize) + ) + .apply(p_311401_, ChestFormedTrigger.Instance::new) + ); - @Override - public ResourceLocation getId() { - return ID; + public void test(ServerPlayer player, ChestMaterial material, int size) { + this.trigger(player, (instance) -> instance.test(player, Pair.of(material, size))); } @Override - public Instance createInstance(JsonObject json, ContextAwarePredicate entityPredicate, DeserializationContext conditionsParser) { - ChestMaterial material = null; - JsonElement element = json.get("material"); - if (element != null && !element.isJsonNull()) { - String materialString = element.getAsString(); - try { - material = Objects.requireNonNull(ChestMaterial.valueOf(materialString), "Could not find a chest material by name " + materialString); - } catch (IllegalArgumentException e) { - throw new JsonSyntaxException("Could not find a colossal chest material by name " + materialString - + ". Allowed values: " - + ChestMaterial.VALUES.stream().map(ChestMaterial::getName).collect(Collectors.toList())); - } - } - - Integer minimumSize = null; - JsonElement elementSize = json.get("minimumSize"); - if (elementSize != null && !elementSize.isJsonNull()) { - minimumSize = GsonHelper.convertToInt(elementSize, "minimumSize"); - } - return new Instance(getId(), entityPredicate, material, minimumSize); + public Codec codec() { + return CODEC; } - public void test(ServerPlayer player, ChestMaterial material, int size) { - this.trigger(player, (instance) -> { - return instance.test(player, Pair.of(material, size)); - }); - } - - public static class Instance extends AbstractCriterionTriggerInstance implements ICriterionInstanceTestable> { - private final ChestMaterial material; - private final Integer minimumSize; - - public Instance(ResourceLocation criterionIn, ContextAwarePredicate player, @Nullable ChestMaterial material, @Nullable Integer minimumSize) { - super(criterionIn, player); - this.material = material; - this.minimumSize = minimumSize; - } - + public static record Instance( + Optional player, + Optional material, + Optional minimumSize + ) implements SimpleCriterionTrigger.SimpleInstance, ICriterionInstanceTestable> { + @Override public boolean test(ServerPlayer player, Pair data) { - return (this.material == null || this.material == data.getLeft()) - && (this.minimumSize == null || this.minimumSize <= data.getRight()); + return this.material.map(mat -> mat == data.getLeft()).orElse(true) + && this.minimumSize.map(size -> size <= data.getRight()).orElse(true); } } diff --git a/src/main/java/org/cyclops/colossalchests/advancement/criterion/ChestFormedTriggerConfig.java b/src/main/java/org/cyclops/colossalchests/advancement/criterion/ChestFormedTriggerConfig.java new file mode 100644 index 00000000..425cbbcc --- /dev/null +++ b/src/main/java/org/cyclops/colossalchests/advancement/criterion/ChestFormedTriggerConfig.java @@ -0,0 +1,23 @@ +package org.cyclops.colossalchests.advancement.criterion; + +import org.cyclops.colossalchests.ColossalChests; +import org.cyclops.cyclopscore.config.extendedconfig.CriterionTriggerConfig; + +/** + * @author rubensworks + * + */ +public class ChestFormedTriggerConfig extends CriterionTriggerConfig { + + /** + * Make a new instance. + */ + public ChestFormedTriggerConfig() { + super( + ColossalChests._instance, + "chest_formed", + new ChestFormedTrigger() + ); + } + +} diff --git a/src/main/java/org/cyclops/colossalchests/block/ChestMaterial.java b/src/main/java/org/cyclops/colossalchests/block/ChestMaterial.java index 89f87ff2..c78128e9 100644 --- a/src/main/java/org/cyclops/colossalchests/block/ChestMaterial.java +++ b/src/main/java/org/cyclops/colossalchests/block/ChestMaterial.java @@ -2,6 +2,9 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import com.google.gson.JsonSyntaxException; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import net.minecraft.core.Vec3i; import net.minecraft.world.inventory.MenuType; import org.cyclops.colossalchests.GeneralConfig; @@ -19,12 +22,20 @@ import java.util.List; import java.util.Map; import java.util.function.Supplier; +import java.util.stream.Collectors; /** * @author rubensworks */ public class ChestMaterial { + public static final Codec CODEC = RecordCodecBuilder.create( + builder -> builder.group( + Codec.STRING.fieldOf("name").forGetter(ChestMaterial::getName) + ) + .apply(builder, ChestMaterial::valueOfSafe) + ); + public static final List VALUES = Lists.newArrayList(); public static final Map KEYED_VALUES = Maps.newHashMap(); @@ -58,6 +69,16 @@ public static ChestMaterial valueOf(String materialString) { return KEYED_VALUES.get(materialString.toLowerCase()); } + public static ChestMaterial valueOfSafe(String materialString) { + ChestMaterial ret = valueOf(materialString); + if (ret == null) { + throw new JsonSyntaxException("Could not find a colossal chest material by name " + materialString + + ". Allowed values: " + + ChestMaterial.VALUES.stream().map(ChestMaterial::getName).collect(Collectors.toList())); + } + return ret; + } + public String getName() { return name; } diff --git a/src/main/java/org/cyclops/colossalchests/block/ColossalChest.java b/src/main/java/org/cyclops/colossalchests/block/ColossalChest.java index f21675e1..cc2cd660 100644 --- a/src/main/java/org/cyclops/colossalchests/block/ColossalChest.java +++ b/src/main/java/org/cyclops/colossalchests/block/ColossalChest.java @@ -1,5 +1,6 @@ package org.cyclops.colossalchests.block; +import com.mojang.serialization.MapCodec; import net.minecraft.ChatFormatting; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -28,6 +29,7 @@ import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.LevelReader; import net.minecraft.world.level.LevelWriter; +import net.minecraft.world.level.block.BaseEntityBlock; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.RenderShape; @@ -41,7 +43,6 @@ import net.minecraft.world.level.material.FluidState; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.Vec3; -import org.cyclops.colossalchests.Advancements; import org.cyclops.colossalchests.RegistryEntries; import org.cyclops.colossalchests.blockentity.BlockEntityColossalChest; import org.cyclops.cyclopscore.block.BlockWithEntityGui; @@ -66,10 +67,12 @@ public class ColossalChest extends BlockWithEntityGui implements CubeDetector.ID public static final BooleanProperty ENABLED = BlockStateProperties.ENABLED; private final ChestMaterial material; + public final MapCodec codec; public ColossalChest(Properties properties, ChestMaterial material) { super(properties, BlockEntityColossalChest::new); this.material = material; + this.codec = simpleCodec((props) -> new ColossalChest(props, material)); material.setBlockCore(this); @@ -86,7 +89,7 @@ public MenuProvider getMenuProvider(BlockState p_49234_, Level p_49235_, BlockPo @Override @Nullable public BlockEntityTicker getTicker(Level level, BlockState blockState, BlockEntityType blockEntityType) { - return level.isClientSide ? createTickerHelper(blockEntityType, RegistryEntries.BLOCK_ENTITY_COLOSSAL_CHEST, BlockEntityColossalChest::lidAnimateTick) : null; + return level.isClientSide ? createTickerHelper(blockEntityType, RegistryEntries.BLOCK_ENTITY_COLOSSAL_CHEST.get(), BlockEntityColossalChest::lidAnimateTick) : null; } @Override @@ -124,6 +127,11 @@ public static boolean canPlace(LevelReader world, BlockPos pos) { return true; } + @Override + protected MapCodec codec() { + return codec; + } + @Override public RenderShape getRenderShape(BlockState blockState) { return blockState.getValue(ENABLED) ? RenderShape.ENTITYBLOCK_ANIMATED : super.getRenderShape(blockState); @@ -155,7 +163,7 @@ public static DetectionResult triggerDetector(ChestMaterial material, LevelAcces tile = BlockEntityHelpers.get(world, corePos, BlockEntityColossalChest.class).orElse(null); } - Advancements.CHEST_FORMED.test((ServerPlayer) player, material, tile.getSizeSingular()); + RegistryEntries.TRIGGER_CHEST_FORMED.get().test((ServerPlayer) player, material, tile.getSizeSingular()); } } return detectionResult; diff --git a/src/main/java/org/cyclops/colossalchests/block/ColossalChestConfig.java b/src/main/java/org/cyclops/colossalchests/block/ColossalChestConfig.java index 4a5f6865..714b10a2 100644 --- a/src/main/java/org/cyclops/colossalchests/block/ColossalChestConfig.java +++ b/src/main/java/org/cyclops/colossalchests/block/ColossalChestConfig.java @@ -3,7 +3,7 @@ import net.minecraft.world.item.Item; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.SoundType; -import net.minecraftforge.fml.config.ModConfig; +import net.neoforged.fml.config.ModConfig; import org.cyclops.colossalchests.ColossalChests; import org.cyclops.colossalchests.item.ItemBlockMaterial; import org.cyclops.cyclopscore.config.ConfigurableProperty; diff --git a/src/main/java/org/cyclops/colossalchests/block/Interface.java b/src/main/java/org/cyclops/colossalchests/block/Interface.java index 8b1b154a..38c15d75 100644 --- a/src/main/java/org/cyclops/colossalchests/block/Interface.java +++ b/src/main/java/org/cyclops/colossalchests/block/Interface.java @@ -1,5 +1,6 @@ package org.cyclops.colossalchests.block; +import com.mojang.serialization.MapCodec; import net.minecraft.core.BlockPos; import net.minecraft.core.Vec3i; import net.minecraft.world.InteractionHand; @@ -16,6 +17,7 @@ import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.LevelReader; import net.minecraft.world.level.LevelWriter; +import net.minecraft.world.level.block.BaseEntityBlock; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.RenderShape; @@ -41,10 +43,12 @@ public class Interface extends BlockWithEntity implements CubeDetector.IDetectio public static final BooleanProperty ENABLED = ColossalChest.ENABLED; private final ChestMaterial material; + public final MapCodec codec; public Interface(Block.Properties properties, ChestMaterial material) { super(properties, BlockEntityInterface::new); this.material = material; + this.codec = simpleCodec((props) -> new Interface(props, material)); material.setBlockInterface(this); @@ -68,6 +72,11 @@ protected void createBlockStateDefinition(StateDefinition.Builder codec() { + return codec; + } + @Override public RenderShape getRenderShape(BlockState blockState) { return blockState.getValue(ENABLED) ? RenderShape.ENTITYBLOCK_ANIMATED : super.getRenderShape(blockState); diff --git a/src/main/java/org/cyclops/colossalchests/block/UncolossalChest.java b/src/main/java/org/cyclops/colossalchests/block/UncolossalChest.java index 6c9963ee..03db992c 100644 --- a/src/main/java/org/cyclops/colossalchests/block/UncolossalChest.java +++ b/src/main/java/org/cyclops/colossalchests/block/UncolossalChest.java @@ -1,5 +1,6 @@ package org.cyclops.colossalchests.block; +import com.mojang.serialization.MapCodec; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.server.level.ServerLevel; @@ -13,6 +14,7 @@ import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.block.BaseEntityBlock; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.HorizontalDirectionalBlock; import net.minecraft.world.level.block.Mirror; @@ -32,8 +34,8 @@ import net.minecraft.world.level.pathfinder.PathComputationType; 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 org.cyclops.colossalchests.RegistryEntries; import org.cyclops.colossalchests.blockentity.BlockEntityUncolossalChest; import org.cyclops.cyclopscore.block.BlockWithEntityGui; @@ -50,6 +52,7 @@ public class UncolossalChest extends BlockWithEntityGui implements SimpleWaterlo public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING; public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; + public static final MapCodec CODEC = simpleCodec(UncolossalChest::new); private final VoxelShape SHAPE = Block.box(5.0D, 0.0D, 5.0D, 11.0D, 6, 11.0D); @@ -61,10 +64,15 @@ public UncolossalChest(Block.Properties properties) { .setValue(WATERLOGGED, false)); } + @Override + protected MapCodec codec() { + return CODEC; + } + @Override @Nullable public BlockEntityTicker getTicker(Level level, BlockState blockState, BlockEntityType blockEntityType) { - return level.isClientSide ? createTickerHelper(blockEntityType, RegistryEntries.BLOCK_ENTITY_UNCOLOSSAL_CHEST, BlockEntityUncolossalChest::lidAnimateTick) : null; + return level.isClientSide ? createTickerHelper(blockEntityType, RegistryEntries.BLOCK_ENTITY_UNCOLOSSAL_CHEST.get(), BlockEntityUncolossalChest::lidAnimateTick) : null; } @Override diff --git a/src/main/java/org/cyclops/colossalchests/block/UncolossalChestConfig.java b/src/main/java/org/cyclops/colossalchests/block/UncolossalChestConfig.java index 3d1fc721..98284301 100644 --- a/src/main/java/org/cyclops/colossalchests/block/UncolossalChestConfig.java +++ b/src/main/java/org/cyclops/colossalchests/block/UncolossalChestConfig.java @@ -4,9 +4,9 @@ import net.minecraft.world.item.Item; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.SoundType; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.client.extensions.common.IClientItemExtensions; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; +import net.neoforged.neoforge.client.extensions.common.IClientItemExtensions; import org.cyclops.colossalchests.ColossalChests; import org.cyclops.colossalchests.client.render.blockentity.ItemStackTileEntityUncolossalChestRender; import org.cyclops.cyclopscore.config.extendedconfig.BlockConfig; diff --git a/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityColossalChest.java b/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityColossalChest.java index 9da6514a..dd4f7320 100644 --- a/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityColossalChest.java +++ b/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityColossalChest.java @@ -5,6 +5,7 @@ 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.nbt.Tag; import net.minecraft.network.chat.Component; @@ -25,16 +26,9 @@ import net.minecraft.world.level.block.entity.ContainerOpenersCounter; import net.minecraft.world.level.block.entity.LidBlockEntity; import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; -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.util.LazyOptional; -import net.minecraftforge.items.IItemHandler; -import net.minecraftforge.items.wrapper.InvWrapper; -import net.minecraftforge.registries.ForgeRegistries; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import org.cyclops.colossalchests.GeneralConfig; import org.cyclops.colossalchests.RegistryEntries; import org.cyclops.colossalchests.block.ChestMaterial; @@ -91,7 +85,6 @@ protected boolean isOwnContainer(Player player) { private SimpleInventory lastValidInventory = null; private SimpleInventory inventory = null; - private LazyOptional capabilityItemHandler = LazyOptional.empty(); @NBTPersist private Vec3i size = LocationHelpers.copyLocation(Vec3i.ZERO); @@ -110,7 +103,7 @@ protected boolean isOwnContainer(Player player) { private EnumFacingMap facingSlots = EnumFacingMap.newMap(); public BlockEntityColossalChest(BlockPos blockPos, BlockState blockState) { - super(RegistryEntries.BLOCK_ENTITY_COLOSSAL_CHEST, blockPos, blockState); + super(RegistryEntries.BLOCK_ENTITY_COLOSSAL_CHEST.get(), blockPos, blockState); } /** @@ -222,8 +215,8 @@ protected LargeInventory constructInventoryDebug() { : new LargeInventory(calculateInventorySize(), 64); Random random = new Random(); for (int i = 0; i < inv.getContainerSize(); i++) { - inv.setItem(i, new ItemStack(Iterables.get(ForgeRegistries.ITEMS.getValues(), - random.nextInt(ForgeRegistries.ITEMS.getValues().size())))); + inv.setItem(i, new ItemStack(Iterables.get(BuiltInRegistries.ITEM, + random.nextInt(BuiltInRegistries.ITEM.size())))); } return inv; } @@ -307,14 +300,8 @@ protected int calculateInventorySize() { } public void setInventory(SimpleInventory inventory) { - this.capabilityItemHandler.invalidate(); + invalidateCapabilities(); this.inventory = inventory; - if (this.inventory.getContainerSize() > 0) { - IItemHandler itemHandler = new InvWrapper(this.inventory); - this.capabilityItemHandler = LazyOptional.of(() -> itemHandler); - } else { - this.capabilityItemHandler = LazyOptional.empty(); - } } protected void ensureInventoryInitialized() { @@ -334,27 +321,11 @@ public INBTInventory getInventory() { return inventory; } - @Override - public LazyOptional getCapability(Capability capability, Direction facing) { - ensureInventoryInitialized(); - if (this.capabilityItemHandler.isPresent() && capability == ForgeCapabilities.ITEM_HANDLER) { - return this.capabilityItemHandler.cast(); - } - return super.getCapability(capability, facing); - } - @Override public boolean canInteractWith(Player entityPlayer) { return getSizeSingular() > 1 && super.canInteractWith(entityPlayer); } - @Override - @OnlyIn(Dist.CLIENT) - public AABB getRenderBoundingBox() { - int size = getSizeSingular(); - return new AABB(getBlockPos().subtract(new Vec3i(size, size, size)), getBlockPos().offset(size, size * 2, size)); - } - public void setCenter(Vec3 center) { Direction rotation; double dx = Math.abs(center.x - getBlockPos().getX()); diff --git a/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityColossalChestConfig.java b/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityColossalChestConfig.java index b9deea4c..352b4c62 100644 --- a/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityColossalChestConfig.java +++ b/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityColossalChestConfig.java @@ -1,8 +1,11 @@ package org.cyclops.colossalchests.blockentity; import net.minecraft.world.level.block.entity.BlockEntityType; -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 net.neoforged.neoforge.capabilities.Capabilities; +import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent; +import net.neoforged.neoforge.items.wrapper.InvWrapper; import org.cyclops.colossalchests.ColossalChests; import org.cyclops.colossalchests.block.ChestMaterial; import org.cyclops.colossalchests.client.render.blockentity.RenderTileEntityColossalChest; @@ -26,6 +29,7 @@ public BlockEntityColossalChestConfig() { .map(ChestMaterial::getBlockCore) .collect(Collectors.toSet()), null) ); + ColossalChests._instance.getModEventBus().addListener(this::registerCapabilities); } @Override @@ -35,4 +39,12 @@ public void onRegistered() { ColossalChests._instance.getProxy().registerRenderer(getInstance(), RenderTileEntityColossalChest::new); } + public void registerCapabilities(RegisterCapabilitiesEvent event) { + event.registerBlockEntity( + Capabilities.ItemHandler.BLOCK, + getInstance(), + (blockEntity, context) -> new InvWrapper(blockEntity.getInventory()) + ); + } + } diff --git a/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityInterface.java b/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityInterface.java index a2f3c362..edc5857b 100644 --- a/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityInterface.java +++ b/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityInterface.java @@ -2,17 +2,13 @@ import lombok.Getter; import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; import net.minecraft.core.Vec3i; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.common.util.LazyOptional; import org.cyclops.colossalchests.RegistryEntries; import org.cyclops.cyclopscore.blockentity.CyclopsBlockEntity; import org.cyclops.cyclopscore.helper.BlockEntityHelpers; import org.cyclops.cyclopscore.persist.nbt.NBTPersist; -import javax.annotation.Nonnull; import java.lang.ref.WeakReference; /** @@ -28,19 +24,7 @@ public class BlockEntityInterface extends CyclopsBlockEntity { private WeakReference coreReference = new WeakReference(null); public BlockEntityInterface(BlockPos blockPos, BlockState blockState) { - super(RegistryEntries.BLOCK_ENTITY_INTERFACE, blockPos, blockState); - } - - @Override - public LazyOptional getCapability(@Nonnull Capability capability, Direction facing) { - BlockEntityColossalChest core = getCore(); - if (core != null) { - LazyOptional t = core.getCapability(capability, facing); - if (t.isPresent()) { - return t; - } - } - return super.getCapability(capability, facing); + super(RegistryEntries.BLOCK_ENTITY_INTERFACE.get(), blockPos, blockState); } public void setCorePosition(Vec3i corePosition) { @@ -48,12 +32,12 @@ public void setCorePosition(Vec3i corePosition) { coreReference = new WeakReference(null); } - protected BlockEntityColossalChest getCore() { + public BlockEntityColossalChest getCore() { if(corePosition == null) { return null; } if (coreReference.get() == null) { - coreReference = new WeakReference( + coreReference = new WeakReference<>( BlockEntityHelpers.get(getLevel(), new BlockPos(corePosition), BlockEntityColossalChest.class).orElse(null)); } return coreReference.get(); diff --git a/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityInterfaceConfig.java b/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityInterfaceConfig.java index 8016ac1e..fa0e6901 100644 --- a/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityInterfaceConfig.java +++ b/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityInterfaceConfig.java @@ -1,6 +1,9 @@ package org.cyclops.colossalchests.blockentity; import net.minecraft.world.level.block.entity.BlockEntityType; +import net.neoforged.neoforge.capabilities.Capabilities; +import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent; +import net.neoforged.neoforge.items.wrapper.InvWrapper; import org.cyclops.colossalchests.ColossalChests; import org.cyclops.colossalchests.block.ChestMaterial; import org.cyclops.cyclopscore.config.extendedconfig.BlockEntityConfig; @@ -23,6 +26,21 @@ public BlockEntityInterfaceConfig() { .map(ChestMaterial::getBlockInterface) .collect(Collectors.toSet()), null) ); + ColossalChests._instance.getModEventBus().addListener(this::registerCapabilities); + } + + public void registerCapabilities(RegisterCapabilitiesEvent event) { + event.registerBlockEntity( + Capabilities.ItemHandler.BLOCK, + getInstance(), + (blockEntity, context) -> { + BlockEntityColossalChest core = blockEntity.getCore(); + if (core != null) { + return new InvWrapper(core.getInventory()); + } + return null; + } + ); } } diff --git a/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityUncolossalChest.java b/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityUncolossalChest.java index 362bf600..d2ac5c9f 100644 --- a/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityUncolossalChest.java +++ b/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityUncolossalChest.java @@ -19,9 +19,6 @@ import net.minecraft.world.level.block.entity.ContainerOpenersCounter; import net.minecraft.world.level.block.entity.LidBlockEntity; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.common.capabilities.ForgeCapabilities; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.items.wrapper.InvWrapper; import org.cyclops.colossalchests.RegistryEntries; import org.cyclops.colossalchests.block.UncolossalChest; import org.cyclops.colossalchests.inventory.container.ContainerUncolossalChest; @@ -67,7 +64,7 @@ protected boolean isOwnContainer(Player player) { private final SimpleInventory inventory; public BlockEntityUncolossalChest(BlockPos blockPos, BlockState blockState) { - super(RegistryEntries.BLOCK_ENTITY_UNCOLOSSAL_CHEST, blockPos, blockState); + super(RegistryEntries.BLOCK_ENTITY_UNCOLOSSAL_CHEST.get(), blockPos, blockState); this.inventory = new SimpleInventory(5, 64) { @Override public void startOpen(Player entityPlayer) { @@ -86,7 +83,6 @@ public void stopOpen(Player entityPlayer) { } }; this.inventory.addDirtyMarkListener(this); - addCapabilityInternal(ForgeCapabilities.ITEM_HANDLER, LazyOptional.of(() -> new InvWrapper(this.inventory))); } public SimpleInventory getInventory() { @@ -181,7 +177,7 @@ public Direction getRotation() { } BlockState blockState = getLevel().getBlockState(getBlockPos()); - if(blockState.getBlock() != RegistryEntries.BLOCK_UNCOLOSSAL_CHEST) return Direction.NORTH; + if(blockState.getBlock() != RegistryEntries.BLOCK_UNCOLOSSAL_CHEST.get()) return Direction.NORTH; return BlockHelpers.getSafeBlockStateProperty(blockState, UncolossalChest.FACING, Direction.NORTH); } diff --git a/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityUncolossalChestConfig.java b/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityUncolossalChestConfig.java index 3490c396..1fcfd329 100644 --- a/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityUncolossalChestConfig.java +++ b/src/main/java/org/cyclops/colossalchests/blockentity/BlockEntityUncolossalChestConfig.java @@ -2,8 +2,11 @@ import com.google.common.collect.Sets; import net.minecraft.world.level.block.entity.BlockEntityType; -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 net.neoforged.neoforge.capabilities.Capabilities; +import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent; +import net.neoforged.neoforge.items.wrapper.InvWrapper; import org.cyclops.colossalchests.ColossalChests; import org.cyclops.colossalchests.RegistryEntries; import org.cyclops.colossalchests.client.render.blockentity.RenderTileEntityUncolossalChest; @@ -21,8 +24,9 @@ public BlockEntityUncolossalChestConfig() { ColossalChests._instance, "uncolossal_chest", (eConfig) -> new BlockEntityType<>(BlockEntityUncolossalChest::new, - Sets.newHashSet(RegistryEntries.BLOCK_UNCOLOSSAL_CHEST), null) + Sets.newHashSet(RegistryEntries.BLOCK_UNCOLOSSAL_CHEST.get()), null) ); + ColossalChests._instance.getModEventBus().addListener(this::registerCapabilities); } @Override @@ -32,4 +36,11 @@ public void onRegistered() { ColossalChests._instance.getProxy().registerRenderer(getInstance(), RenderTileEntityUncolossalChest::new); } + public void registerCapabilities(RegisterCapabilitiesEvent event) { + event.registerBlockEntity( + Capabilities.ItemHandler.BLOCK, + getInstance(), + (blockEntity, context) -> new InvWrapper(blockEntity.getInventory()) + ); + } } diff --git a/src/main/java/org/cyclops/colossalchests/client/render/blockentity/ItemStackTileEntityUncolossalChestRender.java b/src/main/java/org/cyclops/colossalchests/client/render/blockentity/ItemStackTileEntityUncolossalChestRender.java index 369411f5..e6d2cbf8 100644 --- a/src/main/java/org/cyclops/colossalchests/client/render/blockentity/ItemStackTileEntityUncolossalChestRender.java +++ b/src/main/java/org/cyclops/colossalchests/client/render/blockentity/ItemStackTileEntityUncolossalChestRender.java @@ -2,9 +2,9 @@ import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer; import net.minecraft.core.BlockPos; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.client.extensions.common.IClientItemExtensions; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; +import net.neoforged.neoforge.client.extensions.common.IClientItemExtensions; import org.cyclops.colossalchests.RegistryEntries; import org.cyclops.colossalchests.blockentity.BlockEntityUncolossalChest; import org.cyclops.cyclopscore.client.render.blockentity.ItemStackBlockEntityRendererBase; @@ -16,7 +16,7 @@ public class ItemStackTileEntityUncolossalChestRender extends ItemStackBlockEntityRendererBase { public ItemStackTileEntityUncolossalChestRender() { - super(() -> new BlockEntityUncolossalChest(BlockPos.ZERO, RegistryEntries.BLOCK_UNCOLOSSAL_CHEST.defaultBlockState())); + super(() -> new BlockEntityUncolossalChest(BlockPos.ZERO, RegistryEntries.BLOCK_UNCOLOSSAL_CHEST.get().defaultBlockState())); } public static class ClientItemExtensions implements IClientItemExtensions { diff --git a/src/main/java/org/cyclops/colossalchests/client/render/blockentity/RenderTileEntityChestBase.java b/src/main/java/org/cyclops/colossalchests/client/render/blockentity/RenderTileEntityChestBase.java index c6900ae0..132bb243 100644 --- a/src/main/java/org/cyclops/colossalchests/client/render/blockentity/RenderTileEntityChestBase.java +++ b/src/main/java/org/cyclops/colossalchests/client/render/blockentity/RenderTileEntityChestBase.java @@ -16,8 +16,8 @@ import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.LidBlockEntity; import net.minecraft.world.level.block.state.properties.ChestType; -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.Calendar; diff --git a/src/main/java/org/cyclops/colossalchests/client/render/blockentity/RenderTileEntityColossalChest.java b/src/main/java/org/cyclops/colossalchests/client/render/blockentity/RenderTileEntityColossalChest.java index 7bd4810c..5b718055 100644 --- a/src/main/java/org/cyclops/colossalchests/client/render/blockentity/RenderTileEntityColossalChest.java +++ b/src/main/java/org/cyclops/colossalchests/client/render/blockentity/RenderTileEntityColossalChest.java @@ -15,9 +15,10 @@ import net.minecraft.core.Vec3i; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.inventory.InventoryMenu; +import net.minecraft.world.phys.AABB; 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 org.cyclops.colossalchests.GeneralConfig; import org.cyclops.colossalchests.Reference; import org.cyclops.colossalchests.block.ChestMaterial; @@ -61,6 +62,15 @@ public RenderTileEntityColossalChest(BlockEntityRendererProvider.Context context super(context); } + @Override + public AABB getRenderBoundingBox(BlockEntityColossalChest blockEntity) { + int size = blockEntity.getSizeSingular(); + return new AABB( + Vec3.atLowerCornerOf(blockEntity.getBlockPos().subtract(new Vec3i(size, size, size))), + Vec3.atLowerCornerOf(blockEntity.getBlockPos().offset(size, size * 2, size)) + ); + } + @Override protected void handleRotation(BlockEntityColossalChest tile, PoseStack matrixStack) { // Move origin to center of chest diff --git a/src/main/java/org/cyclops/colossalchests/client/render/blockentity/RenderTileEntityUncolossalChest.java b/src/main/java/org/cyclops/colossalchests/client/render/blockentity/RenderTileEntityUncolossalChest.java index eda15581..e8c61f1c 100644 --- a/src/main/java/org/cyclops/colossalchests/client/render/blockentity/RenderTileEntityUncolossalChest.java +++ b/src/main/java/org/cyclops/colossalchests/client/render/blockentity/RenderTileEntityUncolossalChest.java @@ -4,8 +4,8 @@ import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; import net.minecraft.core.Direction; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import org.cyclops.colossalchests.blockentity.BlockEntityUncolossalChest; /** diff --git a/src/main/java/org/cyclops/colossalchests/condition/ConditionMetalVariantsSetting.java b/src/main/java/org/cyclops/colossalchests/condition/ConditionMetalVariantsSetting.java new file mode 100644 index 00000000..5495ba7f --- /dev/null +++ b/src/main/java/org/cyclops/colossalchests/condition/ConditionMetalVariantsSetting.java @@ -0,0 +1,28 @@ +package org.cyclops.colossalchests.condition; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.neoforged.neoforge.common.conditions.ICondition; +import org.cyclops.colossalchests.GeneralConfig; + +/** + * A recipe condition for checking if the {@link GeneralConfig#metalVariants} setting is enabled. + * @author rubensworks + */ +public record ConditionMetalVariantsSetting() implements ICondition { + + public static final Codec CODEC = RecordCodecBuilder.create( + builder -> builder.point(new ConditionMetalVariantsSetting()) + ); + + @Override + public boolean test(IContext context) { + return GeneralConfig.metalVariants; + } + + @Override + public Codec codec() { + return CODEC; + } + +} diff --git a/src/main/java/org/cyclops/colossalchests/condition/ConditionMetalVariantsSettingConfig.java b/src/main/java/org/cyclops/colossalchests/condition/ConditionMetalVariantsSettingConfig.java new file mode 100644 index 00000000..7809f473 --- /dev/null +++ b/src/main/java/org/cyclops/colossalchests/condition/ConditionMetalVariantsSettingConfig.java @@ -0,0 +1,20 @@ +package org.cyclops.colossalchests.condition; + +import org.cyclops.colossalchests.ColossalChests; +import org.cyclops.cyclopscore.config.extendedconfig.ConditionConfig; + +/** + * Config for the metal variants setting recipe condition. + * @author rubensworks + */ +public class ConditionMetalVariantsSettingConfig extends ConditionConfig { + + public ConditionMetalVariantsSettingConfig() { + super( + ColossalChests._instance, + "metal_variants_enabled", + ConditionMetalVariantsSetting.CODEC + ); + } + +} diff --git a/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerColossalChest.java b/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerColossalChest.java index d90e9034..d0bb106a 100644 --- a/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerColossalChest.java +++ b/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerColossalChest.java @@ -2,34 +2,36 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import com.google.gson.JsonParseException; import invtweaks.api.container.ChestContainer; import invtweaks.api.container.ContainerSection; import invtweaks.api.container.ContainerSectionCallback; -import net.minecraft.world.entity.player.Inventory; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.Container; -import net.minecraft.world.inventory.AbstractContainerMenu; -import net.minecraft.world.inventory.ResultSlot; -import net.minecraft.world.inventory.ContainerListener; -import net.minecraft.world.inventory.Slot; -import net.minecraft.world.item.ItemStack; +import net.minecraft.core.NonNullList; import net.minecraft.nbt.ByteArrayTag; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.EndTag; -import net.minecraft.nbt.Tag; import net.minecraft.nbt.IntArrayTag; import net.minecraft.nbt.ListTag; +import net.minecraft.nbt.NbtOps; import net.minecraft.nbt.NumericTag; import net.minecraft.nbt.StringTag; +import net.minecraft.nbt.Tag; import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.server.network.ServerGamePacketListenerImpl; import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; -import net.minecraft.core.NonNullList; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerGamePacketListenerImpl; +import net.minecraft.world.Container; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.ContainerListener; +import net.minecraft.world.inventory.ResultSlot; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; import org.cyclops.colossalchests.ColossalChests; import org.cyclops.colossalchests.GeneralConfig; import org.cyclops.colossalchests.RegistryEntries; -import org.cyclops.colossalchests.network.packet.ClientboundContainerSetSlotPacketLarge; import org.cyclops.colossalchests.network.packet.ClientboundContainerSetContentPacketWindow; +import org.cyclops.colossalchests.network.packet.ClientboundContainerSetSlotPacketLarge; import org.cyclops.cyclopscore.inventory.LargeInventory; import org.cyclops.cyclopscore.inventory.SimpleInventory; import org.cyclops.cyclopscore.inventory.container.ScrollingInventoryContainer; @@ -73,7 +75,7 @@ public ContainerColossalChest(int id, Inventory playerInventory, FriendlyByteBuf } public ContainerColossalChest(int id, Inventory playerInventory, Container inventory) { - super(RegistryEntries.CONTAINER_COLOSSAL_CHEST, id, playerInventory, inventory, Collections.emptyList(), (item, pattern) -> true); + super(RegistryEntries.CONTAINER_COLOSSAL_CHEST.get(), id, playerInventory, inventory, Collections.emptyList(), (item, pattern) -> true); this.chestSlots = Lists.newArrayListWithCapacity(getSizeInventory()); this.inventoryItemStacks = NonNullList.withSize(getSizeInventory(), ItemStack.EMPTY); @@ -252,7 +254,8 @@ public void updateCraftingInventory(ServerPlayer player, List allItem if (itemStack != null) { CompoundTag tag = new CompoundTag(); tag.putInt("slot", i); - tag.put("stack", itemStack.serializeNBT()); + tag.put("stack", ItemStack.CODEC.encodeStart(NbtOps.INSTANCE, itemStack) + .getOrThrow(false, JsonParseException::new)); int tagSize = getTagSize(tag); if (bufferSize + tagSize + 100 < maxBufferSize) { sendList.add(tag); diff --git a/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerColossalChestConfig.java b/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerColossalChestConfig.java index f03aaec8..64794d39 100644 --- a/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerColossalChestConfig.java +++ b/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerColossalChestConfig.java @@ -4,8 +4,8 @@ import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.inventory.MenuAccess; import net.minecraft.world.flag.FeatureFlags; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import org.cyclops.colossalchests.ColossalChests; import org.cyclops.colossalchests.client.gui.container.ContainerScreenColossalChest; import org.cyclops.cyclopscore.client.gui.ScreenFactorySafe; diff --git a/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerUncolossalChest.java b/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerUncolossalChest.java index 36710b93..377a9eaf 100644 --- a/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerUncolossalChest.java +++ b/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerUncolossalChest.java @@ -26,7 +26,7 @@ public ContainerUncolossalChest(int id, Inventory playerInventory) { } public ContainerUncolossalChest(int id, Inventory playerInventory, Container inventory) { - super(RegistryEntries.CONTAINER_UNCOLOSSAL_CHEST, id, playerInventory, inventory); + super(RegistryEntries.CONTAINER_UNCOLOSSAL_CHEST.get(), id, playerInventory, inventory); this.addInventory(inventory, 0, 44, 20, 1, getSizeInventory()); this.addPlayerInventory(playerInventory, 8, 51); diff --git a/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerUncolossalChestConfig.java b/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerUncolossalChestConfig.java index 37f48d93..0c833fd3 100644 --- a/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerUncolossalChestConfig.java +++ b/src/main/java/org/cyclops/colossalchests/inventory/container/ContainerUncolossalChestConfig.java @@ -5,8 +5,8 @@ import net.minecraft.client.gui.screens.Screen; import net.minecraft.world.flag.FeatureFlags; import net.minecraft.world.inventory.MenuType; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import org.cyclops.colossalchests.ColossalChests; import org.cyclops.colossalchests.client.gui.container.ContainerScreenUncolossalChest; import org.cyclops.cyclopscore.client.gui.ScreenFactorySafe; diff --git a/src/main/java/org/cyclops/colossalchests/item/ItemUpgradeTool.java b/src/main/java/org/cyclops/colossalchests/item/ItemUpgradeTool.java index e7cbc504..eadcdd5c 100644 --- a/src/main/java/org/cyclops/colossalchests/item/ItemUpgradeTool.java +++ b/src/main/java/org/cyclops/colossalchests/item/ItemUpgradeTool.java @@ -15,7 +15,7 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.Vec3; -import org.cyclops.colossalchests.Advancements; +import org.cyclops.colossalchests.RegistryEntries; import org.cyclops.colossalchests.block.ChestMaterial; import org.cyclops.colossalchests.block.ChestWall; import org.cyclops.colossalchests.block.ColossalChest; @@ -188,7 +188,7 @@ && consumeItems(player, requiredWalls, true))) { tileInterface.setCorePosition(coreLocation.get()); } - Advancements.CHEST_FORMED.test((ServerPlayer) player, newType, size.getX() + 1); + RegistryEntries.TRIGGER_CHEST_FORMED.get().test((ServerPlayer) player, newType, size.getX() + 1); } // Add the lower tier items to the players inventory again. diff --git a/src/main/java/org/cyclops/colossalchests/modcompat/CommonCapabilitiesModCompat.java b/src/main/java/org/cyclops/colossalchests/modcompat/CommonCapabilitiesModCompat.java index 5988be70..76fd9c3f 100644 --- a/src/main/java/org/cyclops/colossalchests/modcompat/CommonCapabilitiesModCompat.java +++ b/src/main/java/org/cyclops/colossalchests/modcompat/CommonCapabilitiesModCompat.java @@ -1,26 +1,23 @@ package org.cyclops.colossalchests.modcompat; -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.common.capabilities.ForgeCapabilities; -import net.minecraftforge.common.capabilities.ICapabilityProvider; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.items.IItemHandler; -import org.cyclops.colossalchests.Capabilities; +import net.minecraft.core.Direction; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.neoforged.neoforge.capabilities.BaseCapability; +import net.neoforged.neoforge.capabilities.ICapabilityProvider; +import net.neoforged.neoforge.items.wrapper.InvWrapper; import org.cyclops.colossalchests.ColossalChests; import org.cyclops.colossalchests.Reference; +import org.cyclops.colossalchests.RegistryEntries; import org.cyclops.colossalchests.blockentity.BlockEntityColossalChest; +import org.cyclops.colossalchests.blockentity.BlockEntityInterface; import org.cyclops.commoncapabilities.api.capability.inventorystate.IInventoryState; import org.cyclops.commoncapabilities.api.capability.itemhandler.ISlotlessItemHandler; -import org.cyclops.cyclopscore.datastructure.Wrapper; import org.cyclops.cyclopscore.inventory.IndexedSlotlessItemHandlerWrapper; import org.cyclops.cyclopscore.inventory.SimpleInventory; import org.cyclops.cyclopscore.modcompat.ICompatInitializer; import org.cyclops.cyclopscore.modcompat.IModCompat; import org.cyclops.cyclopscore.modcompat.capabilities.CapabilityConstructorRegistry; -import org.cyclops.cyclopscore.modcompat.capabilities.DefaultCapabilityProvider; -import org.cyclops.cyclopscore.modcompat.capabilities.SimpleCapabilityConstructor; - -import javax.annotation.Nullable; +import org.cyclops.cyclopscore.modcompat.capabilities.ICapabilityConstructor; /** * Mod compat for the Common Capabilities mod. @@ -48,41 +45,70 @@ public String getComment() { public ICompatInitializer createInitializer() { return () -> { CapabilityConstructorRegistry registry = ColossalChests._instance.getCapabilityConstructorRegistry(); + // Slotless item handler - registry.registerTile(BlockEntityColossalChest.class, - new SimpleCapabilityConstructor() { + registry.registerBlockEntity(RegistryEntries.BLOCK_ENTITY_COLOSSAL_CHEST::get, + new ICapabilityConstructor>() { + @Override + public BaseCapability getCapability() { + return org.cyclops.commoncapabilities.api.capability.Capabilities.SlotlessItemHandler.BLOCK; + } + + @Override + public ICapabilityProvider createProvider(BlockEntityType capabilityKey) { + return (blockEntity, side) -> new IndexedSlotlessItemHandlerWrapper(new InvWrapper(blockEntity.getInventory()), + (IndexedSlotlessItemHandlerWrapper.IInventoryIndexReference) blockEntity.getInventory()); + } + }); + registry.registerBlockEntity(RegistryEntries.BLOCK_ENTITY_INTERFACE::get, + new ICapabilityConstructor>() { @Override - public Capability getCapability() { - return Capabilities.SLOTLESS_ITEMHANDLER; + public BaseCapability getCapability() { + return org.cyclops.commoncapabilities.api.capability.Capabilities.SlotlessItemHandler.BLOCK; } - @Nullable @Override - public ICapabilityProvider createProvider(BlockEntityColossalChest host) { - // Wrapper hack because Java otherwise complains that the optionalSlotlessItemHandler may not be initialized yet, and it won't compile. - Wrapper> optionalSlotlessItemHandler = new Wrapper<>(); - optionalSlotlessItemHandler.set(LazyOptional.of(() -> { - LazyOptional optionalItemHandler = host.getCapability(ForgeCapabilities.ITEM_HANDLER); - optionalItemHandler.addListener((o) -> optionalSlotlessItemHandler.get().invalidate()); - return new IndexedSlotlessItemHandlerWrapper(optionalItemHandler.orElse(null), - (IndexedSlotlessItemHandlerWrapper.IInventoryIndexReference) host.getInventory()); - })); - return new DefaultCapabilityProvider<>(this::getCapability, optionalSlotlessItemHandler.get()); + public ICapabilityProvider createProvider(BlockEntityType capabilityKey) { + return (blockEntity, side) -> { + BlockEntityColossalChest core = blockEntity.getCore(); + if (core != null) { + return new IndexedSlotlessItemHandlerWrapper(new InvWrapper(core.getInventory()), + (IndexedSlotlessItemHandlerWrapper.IInventoryIndexReference) core.getInventory()); + } + return null; + }; } }); + // Inventory state - registry.registerTile(BlockEntityColossalChest.class, - new SimpleCapabilityConstructor() { + registry.registerBlockEntity(RegistryEntries.BLOCK_ENTITY_COLOSSAL_CHEST::get, + new ICapabilityConstructor>() { + @Override + public BaseCapability getCapability() { + return org.cyclops.commoncapabilities.api.capability.Capabilities.InventoryState.BLOCK; + } + + @Override + public ICapabilityProvider createProvider(BlockEntityType capabilityKey) { + return (blockEntity, side) -> () -> ((SimpleInventory) blockEntity.getInventory()).getState(); + } + }); + registry.registerBlockEntity(RegistryEntries.BLOCK_ENTITY_INTERFACE::get, + new ICapabilityConstructor>() { @Override - public Capability getCapability() { - return Capabilities.INVENTORY_STATE; + public BaseCapability getCapability() { + return org.cyclops.commoncapabilities.api.capability.Capabilities.InventoryState.BLOCK; } - @Nullable @Override - public ICapabilityProvider createProvider(BlockEntityColossalChest host) { - return new DefaultCapabilityProvider<>(this::getCapability, - LazyOptional.of(() -> () -> ((SimpleInventory) host.getInventory()).getState())); + public ICapabilityProvider createProvider(BlockEntityType capabilityKey) { + return (blockEntity, side) -> { + BlockEntityColossalChest core = blockEntity.getCore(); + if (core != null) { + return () -> ((SimpleInventory) core.getInventory()).getState(); + } + return null; + }; } }); }; diff --git a/src/main/java/org/cyclops/colossalchests/modcompat/IronChestModCompat.java b/src/main/java/org/cyclops/colossalchests/modcompat/IronChestModCompat.java index 70c0b519..5dbed2a7 100644 --- a/src/main/java/org/cyclops/colossalchests/modcompat/IronChestModCompat.java +++ b/src/main/java/org/cyclops/colossalchests/modcompat/IronChestModCompat.java @@ -1,8 +1,8 @@ package org.cyclops.colossalchests.modcompat; 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 org.cyclops.colossalchests.Reference; import org.cyclops.colossalchests.block.ChestMaterial; import org.cyclops.colossalchests.client.render.blockentity.RenderTileEntityColossalChest; diff --git a/src/main/java/org/cyclops/colossalchests/network/packet/ClientboundContainerSetContentPacketWindow.java b/src/main/java/org/cyclops/colossalchests/network/packet/ClientboundContainerSetContentPacketWindow.java index 1d4350c6..317de9be 100644 --- a/src/main/java/org/cyclops/colossalchests/network/packet/ClientboundContainerSetContentPacketWindow.java +++ b/src/main/java/org/cyclops/colossalchests/network/packet/ClientboundContainerSetContentPacketWindow.java @@ -4,13 +4,15 @@ import net.minecraft.nbt.ListTag; import net.minecraft.nbt.Tag; import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerPlayer; 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.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; +import org.cyclops.colossalchests.Reference; import org.cyclops.cyclopscore.network.CodecField; import org.cyclops.cyclopscore.network.PacketCodec; @@ -22,6 +24,8 @@ */ public class ClientboundContainerSetContentPacketWindow extends PacketCodec { + public static final ResourceLocation ID = new ResourceLocation(Reference.MOD_ID, "clientbound_container_set_content_packet_window"); + @CodecField private int windowId; @CodecField @@ -30,10 +34,11 @@ public class ClientboundContainerSetContentPacketWindow extends PacketCodec { private CompoundTag itemStacks; public ClientboundContainerSetContentPacketWindow() { - + super(ID); } public ClientboundContainerSetContentPacketWindow(int windowId, int stateId, CompoundTag itemStacks) { + super(ID); this.windowId = windowId; this.stateId = stateId; this.itemStacks = itemStacks; diff --git a/src/main/java/org/cyclops/colossalchests/network/packet/ClientboundContainerSetSlotPacketLarge.java b/src/main/java/org/cyclops/colossalchests/network/packet/ClientboundContainerSetSlotPacketLarge.java index d5d0a450..1bbbe02a 100644 --- a/src/main/java/org/cyclops/colossalchests/network/packet/ClientboundContainerSetSlotPacketLarge.java +++ b/src/main/java/org/cyclops/colossalchests/network/packet/ClientboundContainerSetSlotPacketLarge.java @@ -1,12 +1,14 @@ package org.cyclops.colossalchests.network.packet; import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; +import org.cyclops.colossalchests.Reference; import org.cyclops.cyclopscore.network.CodecField; import org.cyclops.cyclopscore.network.PacketCodec; @@ -18,6 +20,8 @@ */ public class ClientboundContainerSetSlotPacketLarge extends PacketCodec { + public static final ResourceLocation ID = new ResourceLocation(Reference.MOD_ID, "clientbound_container_set_slot_packet_large"); + @CodecField private int windowId; @CodecField @@ -28,10 +32,11 @@ public class ClientboundContainerSetSlotPacketLarge extends PacketCodec { private ItemStack itemStack; public ClientboundContainerSetSlotPacketLarge() { - + super(ID); } public ClientboundContainerSetSlotPacketLarge(int windowId, int stateId, int slot, ItemStack itemStack) { + super(ID); this.windowId = windowId; this.stateId = stateId; this.slot = slot; diff --git a/src/main/java/org/cyclops/colossalchests/network/packet/ServerboundContainerClickPacketOverride.java b/src/main/java/org/cyclops/colossalchests/network/packet/ServerboundContainerClickPacketOverride.java index d94e1775..b3b9d502 100644 --- a/src/main/java/org/cyclops/colossalchests/network/packet/ServerboundContainerClickPacketOverride.java +++ b/src/main/java/org/cyclops/colossalchests/network/packet/ServerboundContainerClickPacketOverride.java @@ -7,13 +7,15 @@ import net.minecraft.core.NonNullList; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.protocol.game.ServerboundContainerClickPacket; +import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.ClickType; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; +import org.cyclops.colossalchests.Reference; import org.cyclops.colossalchests.inventory.container.ContainerColossalChest; import org.cyclops.cyclopscore.network.CodecField; import org.cyclops.cyclopscore.network.PacketCodec; @@ -29,6 +31,8 @@ */ public class ServerboundContainerClickPacketOverride extends PacketCodec { + public static final ResourceLocation ID = new ResourceLocation(Reference.MOD_ID, "serverbound_container_click_packet_override"); + @CodecField private int windowId; @CodecField @@ -44,10 +48,11 @@ public class ServerboundContainerClickPacketOverride extends PacketCodec { private Int2ObjectMap changedSlots; public ServerboundContainerClickPacketOverride() { - + super(ID); } public ServerboundContainerClickPacketOverride(int windowId, int stateId, int slotId, int usedButton, ClickType mode, ItemStack clickedItem, Int2ObjectMap changedSlots) { + super(ID); this.windowId = windowId; this.stateId = stateId; this.slotId = slotId; diff --git a/src/main/java/org/cyclops/colossalchests/proxy/CommonProxy.java b/src/main/java/org/cyclops/colossalchests/proxy/CommonProxy.java index b7f3d952..24857d26 100644 --- a/src/main/java/org/cyclops/colossalchests/proxy/CommonProxy.java +++ b/src/main/java/org/cyclops/colossalchests/proxy/CommonProxy.java @@ -1,9 +1,9 @@ package org.cyclops.colossalchests.proxy; import org.cyclops.colossalchests.ColossalChests; -import org.cyclops.colossalchests.network.packet.ServerboundContainerClickPacketOverride; -import org.cyclops.colossalchests.network.packet.ClientboundContainerSetSlotPacketLarge; import org.cyclops.colossalchests.network.packet.ClientboundContainerSetContentPacketWindow; +import org.cyclops.colossalchests.network.packet.ClientboundContainerSetSlotPacketLarge; +import org.cyclops.colossalchests.network.packet.ServerboundContainerClickPacketOverride; import org.cyclops.cyclopscore.init.ModBase; import org.cyclops.cyclopscore.network.PacketHandler; import org.cyclops.cyclopscore.proxy.CommonProxyComponent; @@ -25,9 +25,9 @@ public void registerPacketHandlers(PacketHandler packetHandler) { super.registerPacketHandlers(packetHandler); // Register packets. - packetHandler.register(ClientboundContainerSetContentPacketWindow.class); - packetHandler.register(ServerboundContainerClickPacketOverride.class); - packetHandler.register(ClientboundContainerSetSlotPacketLarge.class); + packetHandler.register(ClientboundContainerSetContentPacketWindow.ID, ClientboundContainerSetContentPacketWindow::new); + packetHandler.register(ServerboundContainerClickPacketOverride.ID, ServerboundContainerClickPacketOverride::new); + packetHandler.register(ClientboundContainerSetSlotPacketLarge.ID, ClientboundContainerSetSlotPacketLarge::new); } } diff --git a/src/main/java/org/cyclops/colossalchests/recipe/condition/RecipeConditionMetalVariantsSetting.java b/src/main/java/org/cyclops/colossalchests/recipe/condition/RecipeConditionMetalVariantsSetting.java deleted file mode 100644 index f6e61dd4..00000000 --- a/src/main/java/org/cyclops/colossalchests/recipe/condition/RecipeConditionMetalVariantsSetting.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.cyclops.colossalchests.recipe.condition; - -import com.google.gson.JsonObject; -import net.minecraft.resources.ResourceLocation; -import net.minecraftforge.common.crafting.conditions.ICondition; -import net.minecraftforge.common.crafting.conditions.IConditionSerializer; -import org.cyclops.colossalchests.GeneralConfig; -import org.cyclops.colossalchests.Reference; - -/** - * A recipe condition for checking if the {@link GeneralConfig#metalVariants} setting is enabled. - * @author rubensworks - */ -public class RecipeConditionMetalVariantsSetting implements ICondition { - - private static final ResourceLocation NAME = new ResourceLocation(Reference.MOD_ID, "metal_variants_enabled"); - - @Override - public ResourceLocation getID() { - return NAME; - } - - @Override - public boolean test(IContext context) { - return GeneralConfig.metalVariants; - } - - public static class Serializer implements IConditionSerializer { - - public static final RecipeConditionMetalVariantsSetting.Serializer INSTANCE = new RecipeConditionMetalVariantsSetting.Serializer(); - - @Override - public void write(JsonObject json, RecipeConditionMetalVariantsSetting value) { - - } - - @Override - public RecipeConditionMetalVariantsSetting read(JsonObject json) { - return new RecipeConditionMetalVariantsSetting(); - } - - @Override - public ResourceLocation getID() { - return RecipeConditionMetalVariantsSetting.NAME; - } - } - -} diff --git a/src/main/java/org/cyclops/colossalchests/recipe/condition/RecipeConditionMetalVariantsSettingConfig.java b/src/main/java/org/cyclops/colossalchests/recipe/condition/RecipeConditionMetalVariantsSettingConfig.java deleted file mode 100644 index 4337644a..00000000 --- a/src/main/java/org/cyclops/colossalchests/recipe/condition/RecipeConditionMetalVariantsSettingConfig.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.cyclops.colossalchests.recipe.condition; - -import org.cyclops.colossalchests.ColossalChests; -import org.cyclops.cyclopscore.config.extendedconfig.RecipeConditionConfig; - -/** - * Config for the metal variants setting recipe condition. - * @author rubensworks - */ -public class RecipeConditionMetalVariantsSettingConfig extends RecipeConditionConfig { - - public RecipeConditionMetalVariantsSettingConfig() { - super( - ColossalChests._instance, - RecipeConditionMetalVariantsSetting.Serializer.INSTANCE - ); - } - -} diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg index 21be0fc4..605facd6 100644 --- a/src/main/resources/META-INF/accesstransformer.cfg +++ b/src/main/resources/META-INF/accesstransformer.cfg @@ -1,5 +1,2 @@ -# Networking -public net.minecraft.server.network.ServerGamePacketListenerImpl f_9752_ # pendingTransactions - # Guis -public net.minecraft.world.inventory.AbstractContainerMenu f_38848_ # listeners \ No newline at end of file +public net.minecraft.world.inventory.AbstractContainerMenu containerListeners \ 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 719d4b33..ab16fe16 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -1,5 +1,5 @@ modLoader="javafml" -loaderVersion="[47,)" +loaderVersion="[2,)" issueTrackerURL="https://github.com/CyclopsMC/ColossalChests/issues" displayURL="https://www.curseforge.com/minecraft/mc-mods/colossalchests" license="MIT" @@ -13,21 +13,23 @@ updateJSONURL="https://raw.githubusercontent.com/CyclopsMC/Versions/master/forge description=''' For when regular chests are too small. ''' +[[accessTransformers]] + file="META-INF/accesstransformer.cfg" [[dependencies.colossalchests]] modId="cyclopscore" - mandatory=true - versionRange="[1.18.4,)" + type="required" + versionRange="[1.19.0,)" ordering="NONE" side="BOTH" [[dependencies.colossalchests]] - modId="forge" - mandatory=true - versionRange="[47.0.1,)" + modId="neoforge" + type="required" + versionRange="[20.4,)" ordering="NONE" side="BOTH" [[dependencies.colossalchests]] modId="minecraft" - mandatory=true - versionRange="[1.20.1,]" + type="required" + versionRange="[1.20.4,]" ordering="NONE" side="BOTH" diff --git a/src/main/resources/data/colossalchests/advancements/base/copper.json b/src/main/resources/data/colossalchests/advancements/base/copper.json index ddc8dfcf..d9a50b45 100644 --- a/src/main/resources/data/colossalchests/advancements/base/copper.json +++ b/src/main/resources/data/colossalchests/advancements/base/copper.json @@ -15,7 +15,7 @@ "criteria_0": { "trigger": "colossalchests:chest_formed", "conditions": { - "material": "COPPER" + "material": { "name": "COPPER" } } } } diff --git a/src/main/resources/data/colossalchests/advancements/base/diamond.json b/src/main/resources/data/colossalchests/advancements/base/diamond.json index ee1c8d06..fd2090df 100644 --- a/src/main/resources/data/colossalchests/advancements/base/diamond.json +++ b/src/main/resources/data/colossalchests/advancements/base/diamond.json @@ -15,7 +15,7 @@ "criteria_0": { "trigger": "colossalchests:chest_formed", "conditions": { - "material": "DIAMOND" + "material": { "name": "DIAMOND" } } } } diff --git a/src/main/resources/data/colossalchests/advancements/base/gold.json b/src/main/resources/data/colossalchests/advancements/base/gold.json index 97e5636c..20eec51b 100644 --- a/src/main/resources/data/colossalchests/advancements/base/gold.json +++ b/src/main/resources/data/colossalchests/advancements/base/gold.json @@ -15,7 +15,7 @@ "criteria_0": { "trigger": "colossalchests:chest_formed", "conditions": { - "material": "GOLD" + "material": { "name": "GOLD" } } } } diff --git a/src/main/resources/data/colossalchests/advancements/base/iron.json b/src/main/resources/data/colossalchests/advancements/base/iron.json index 92b6ff66..d52e5243 100644 --- a/src/main/resources/data/colossalchests/advancements/base/iron.json +++ b/src/main/resources/data/colossalchests/advancements/base/iron.json @@ -15,7 +15,7 @@ "criteria_0": { "trigger": "colossalchests:chest_formed", "conditions": { - "material": "IRON" + "material": { "name": "IRON" } } } } diff --git a/src/main/resources/data/colossalchests/advancements/base/obsidian.json b/src/main/resources/data/colossalchests/advancements/base/obsidian.json index f609552a..0245d614 100644 --- a/src/main/resources/data/colossalchests/advancements/base/obsidian.json +++ b/src/main/resources/data/colossalchests/advancements/base/obsidian.json @@ -15,7 +15,7 @@ "criteria_0": { "trigger": "colossalchests:chest_formed", "conditions": { - "material": "OBSIDIAN" + "material": { "name": "OBSIDIAN" } } } } diff --git a/src/main/resources/data/colossalchests/advancements/base/silver.json b/src/main/resources/data/colossalchests/advancements/base/silver.json index 194058f9..faa2346a 100644 --- a/src/main/resources/data/colossalchests/advancements/base/silver.json +++ b/src/main/resources/data/colossalchests/advancements/base/silver.json @@ -15,7 +15,7 @@ "criteria_0": { "trigger": "colossalchests:chest_formed", "conditions": { - "material": "SILVER" + "material": { "name": "SILVER" } } } } diff --git a/src/main/resources/data/colossalchests/advancements/base/wood.json b/src/main/resources/data/colossalchests/advancements/base/wood.json index 90867cd9..aee50a48 100644 --- a/src/main/resources/data/colossalchests/advancements/base/wood.json +++ b/src/main/resources/data/colossalchests/advancements/base/wood.json @@ -15,7 +15,7 @@ "criteria_0": { "trigger": "colossalchests:chest_formed", "conditions": { - "material": "WOOD" + "material": { "name": "WOOD" } } } } diff --git a/src/main/resources/data/colossalchests/advancements/size/copper.json b/src/main/resources/data/colossalchests/advancements/size/copper.json index 9a3c5a01..de2f7eb1 100644 --- a/src/main/resources/data/colossalchests/advancements/size/copper.json +++ b/src/main/resources/data/colossalchests/advancements/size/copper.json @@ -16,7 +16,7 @@ "criteria_0": { "trigger": "colossalchests:chest_formed", "conditions": { - "material": "COPPER", + "material": { "name": "COPPER" }, "minimumSize": 10 } } diff --git a/src/main/resources/data/colossalchests/advancements/size/diamond.json b/src/main/resources/data/colossalchests/advancements/size/diamond.json index 13b8d53b..75638c76 100644 --- a/src/main/resources/data/colossalchests/advancements/size/diamond.json +++ b/src/main/resources/data/colossalchests/advancements/size/diamond.json @@ -16,7 +16,7 @@ "criteria_0": { "trigger": "colossalchests:chest_formed", "conditions": { - "material": "DIAMOND", + "material": { "name": "DIAMOND" }, "minimumSize": 10 } } diff --git a/src/main/resources/data/colossalchests/advancements/size/gold.json b/src/main/resources/data/colossalchests/advancements/size/gold.json index 567275a4..1951c356 100644 --- a/src/main/resources/data/colossalchests/advancements/size/gold.json +++ b/src/main/resources/data/colossalchests/advancements/size/gold.json @@ -16,7 +16,7 @@ "criteria_0": { "trigger": "colossalchests:chest_formed", "conditions": { - "material": "GOLD", + "material": { "name": "GOLD" }, "minimumSize": 10 } } diff --git a/src/main/resources/data/colossalchests/advancements/size/iron.json b/src/main/resources/data/colossalchests/advancements/size/iron.json index 04f85a15..ee4edadc 100644 --- a/src/main/resources/data/colossalchests/advancements/size/iron.json +++ b/src/main/resources/data/colossalchests/advancements/size/iron.json @@ -16,7 +16,7 @@ "criteria_0": { "trigger": "colossalchests:chest_formed", "conditions": { - "material": "IRON", + "material": { "name": "IRON" }, "minimumSize": 10 } } diff --git a/src/main/resources/data/colossalchests/advancements/size/obsidian.json b/src/main/resources/data/colossalchests/advancements/size/obsidian.json index 7e056fa5..517ce775 100644 --- a/src/main/resources/data/colossalchests/advancements/size/obsidian.json +++ b/src/main/resources/data/colossalchests/advancements/size/obsidian.json @@ -16,7 +16,7 @@ "criteria_0": { "trigger": "colossalchests:chest_formed", "conditions": { - "material": "OBSIDIAN", + "material": { "name": "OBSIDIAN" }, "minimumSize": 10 } } diff --git a/src/main/resources/data/colossalchests/advancements/size/silver.json b/src/main/resources/data/colossalchests/advancements/size/silver.json index 52b9cfbb..2cbee4d8 100644 --- a/src/main/resources/data/colossalchests/advancements/size/silver.json +++ b/src/main/resources/data/colossalchests/advancements/size/silver.json @@ -16,7 +16,7 @@ "criteria_0": { "trigger": "colossalchests:chest_formed", "conditions": { - "material": "SILVER", + "material": { "name": "SILVER" }, "minimumSize": 10 } } diff --git a/src/main/resources/data/colossalchests/advancements/size/wood.json b/src/main/resources/data/colossalchests/advancements/size/wood.json index fef6f430..71e815a3 100644 --- a/src/main/resources/data/colossalchests/advancements/size/wood.json +++ b/src/main/resources/data/colossalchests/advancements/size/wood.json @@ -16,7 +16,7 @@ "criteria_0": { "trigger": "colossalchests:chest_formed", "conditions": { - "material": "WOOD", + "material": { "name": "WOOD" }, "minimumSize": 10 } }