From 9ff846b8c376e551c3b7bc94c8b73dd0e9c5b95c Mon Sep 17 00:00:00 2001 From: Ruben Taelman Date: Fri, 21 Jun 2024 21:10:17 +0200 Subject: [PATCH] Use BlockEntityCapabilityRegistrar --- gradle.properties | 4 +-- .../BlockEntityScriptingDrive.java | 33 +++++++++++-------- .../BlockEntityScriptingDriveConfig.java | 8 ++--- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/gradle.properties b/gradle.properties index 38ef3c99..6bbcdec8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,8 +2,8 @@ mod_id=integratedscripting mod_version=1.0.1 minecraft_version=1.20.4 neoforge_version=20.4.160-beta -cyclopscore_version=1.19.0-423 -integrateddynamics_version=1.21.2-744 +cyclopscore_version=1.19.0-429 +integrateddynamics_version=1.21.2-748 release_type=release fingerprint=bd0353b3e8a2810d60dd584e256e364bc3bedd44 diff --git a/src/main/java/org/cyclops/integratedscripting/blockentity/BlockEntityScriptingDrive.java b/src/main/java/org/cyclops/integratedscripting/blockentity/BlockEntityScriptingDrive.java index 127d2bec..4f92598a 100644 --- a/src/main/java/org/cyclops/integratedscripting/blockentity/BlockEntityScriptingDrive.java +++ b/src/main/java/org/cyclops/integratedscripting/blockentity/BlockEntityScriptingDrive.java @@ -11,7 +11,6 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; -import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent; import org.cyclops.cyclopscore.datastructure.DimPos; import org.cyclops.cyclopscore.inventory.SimpleInventory; import org.cyclops.cyclopscore.persist.IDirtyMarkListener; @@ -27,6 +26,7 @@ import org.cyclops.integratedscripting.item.ItemScriptingDisk; import javax.annotation.Nullable; +import java.util.function.Supplier; /** * A part entity used to store variables. @@ -47,19 +47,24 @@ public BlockEntityScriptingDrive(BlockPos blockPos, BlockState blockState) { getInventory().addDirtyMarkListener(this); } - public static void registerScriptingDriveCapabilities(RegisterCapabilitiesEvent event, BlockEntityType blockEntityType) { - BlockEntityCableConnectableInventory.registerCableConnectableInventoryCapabilities(event, blockEntityType); - - event.registerBlockEntity( - net.neoforged.neoforge.capabilities.Capabilities.ItemHandler.BLOCK, - blockEntityType, - (blockEntity, context) -> blockEntity.getInventory().getItemHandler() - ); - event.registerBlockEntity( - Capabilities.NetworkElementProvider.BLOCK, - blockEntityType, - (blockEntity, context) -> blockEntity.getNetworkElementProvider() - ); + public static class CapabilityRegistrar extends BlockEntityCableConnectableInventory.CapabilityRegistrar { + public CapabilityRegistrar(Supplier> blockEntityType) { + super(blockEntityType); + } + + @Override + public void populate() { + super.populate(); + + add( + net.neoforged.neoforge.capabilities.Capabilities.ItemHandler.BLOCK, + (blockEntity, context) -> blockEntity.getInventory().getItemHandler() + ); + add( + Capabilities.NetworkElementProvider.BLOCK, + (blockEntity, context) -> blockEntity.getNetworkElementProvider() + ); + } } @Override diff --git a/src/main/java/org/cyclops/integratedscripting/blockentity/BlockEntityScriptingDriveConfig.java b/src/main/java/org/cyclops/integratedscripting/blockentity/BlockEntityScriptingDriveConfig.java index 79e95576..859b573c 100644 --- a/src/main/java/org/cyclops/integratedscripting/blockentity/BlockEntityScriptingDriveConfig.java +++ b/src/main/java/org/cyclops/integratedscripting/blockentity/BlockEntityScriptingDriveConfig.java @@ -2,8 +2,8 @@ import com.google.common.collect.Sets; import net.minecraft.world.level.block.entity.BlockEntityType; -import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent; import org.cyclops.cyclopscore.config.extendedconfig.BlockEntityConfig; +import org.cyclops.integrateddynamics.IntegratedDynamics; import org.cyclops.integratedscripting.IntegratedScripting; import org.cyclops.integratedscripting.RegistryEntries; @@ -21,11 +21,7 @@ public BlockEntityScriptingDriveConfig() { (eConfig) -> new BlockEntityType<>(BlockEntityScriptingDrive::new, Sets.newHashSet(RegistryEntries.BLOCK_SCRIPTING_DRIVE.get()), null) ); - IntegratedScripting._instance.getModEventBus().addListener(this::registerCapability); - } - - protected void registerCapability(RegisterCapabilitiesEvent event) { - BlockEntityScriptingDrive.registerScriptingDriveCapabilities(event, getInstance()); + IntegratedDynamics._instance.getModEventBus().addListener(new BlockEntityScriptingDrive.CapabilityRegistrar(this::getInstance)::register); } }