From 9da84e19e2de36ed421f58459ce0a0c42d439fca Mon Sep 17 00:00:00 2001 From: Ruben Taelman Date: Fri, 21 Jun 2024 21:48:28 +0200 Subject: [PATCH] Use BlockEntityCapabilityRegistrar --- gradle.properties | 4 +- .../blockentity/BlockEntityHttp.java | 55 ++++++++++--------- .../blockentity/BlockEntityHttpConfig.java | 7 +-- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/gradle.properties b/gradle.properties index 338c05e..c72e973 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,8 +2,8 @@ mod_id=integratedrest mod_version=1.1.10 minecraft_version=1.20.4 neoforge_version=20.4.160-beta -cyclopscore_version=1.19.0-423 -integrateddynamics_version=1.21.2-741 +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/integratedrest/blockentity/BlockEntityHttp.java b/src/main/java/org/cyclops/integratedrest/blockentity/BlockEntityHttp.java index 4eccf73..d13adca 100644 --- a/src/main/java/org/cyclops/integratedrest/blockentity/BlockEntityHttp.java +++ b/src/main/java/org/cyclops/integratedrest/blockentity/BlockEntityHttp.java @@ -13,7 +13,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.capability.item.ItemHandlerSlotMasked; import org.cyclops.cyclopscore.datastructure.DimPos; import org.cyclops.integrateddynamics.Capabilities; @@ -30,7 +29,7 @@ import org.cyclops.integrateddynamics.api.network.IPartNetwork; import org.cyclops.integrateddynamics.blockentity.BlockEntityProxy; import org.cyclops.integrateddynamics.capability.networkelementprovider.NetworkElementProviderSingleton; -import org.cyclops.integrateddynamics.core.blockentity.BlockEntityActiveVariableBase; +import org.cyclops.integrateddynamics.core.blockentity.BlockEntityCableConnectableInventory; import org.cyclops.integrateddynamics.core.evaluate.variable.ValueHelpers; import org.cyclops.integrateddynamics.core.evaluate.variable.ValueTypeBoolean; import org.cyclops.integrateddynamics.core.evaluate.variable.ValueTypes; @@ -43,6 +42,7 @@ import javax.annotation.Nullable; import java.util.Optional; +import java.util.function.Supplier; /** * A tile entity for the http block. @@ -65,30 +65,35 @@ public BlockEntityHttp(BlockPos blockPos, BlockState blockState) { this.variable = new HttpVariableAdapter(this, ValueTypes.CATEGORY_ANY, ValueTypeBoolean.ValueBoolean.of(false)); } - public static void registerHttpCapabilities(RegisterCapabilitiesEvent event, BlockEntityType blockEntityType) { - BlockEntityActiveVariableBase.registerActiveVariableBaseCapabilities(event, blockEntityType); - - event.registerBlockEntity( - net.neoforged.neoforge.capabilities.Capabilities.ItemHandler.BLOCK, - blockEntityType, - (blockEntity, direction) -> { - int slot = -1; - switch (direction) { - case DOWN -> slot = SLOT_WRITE_OUT; - case UP -> slot = SLOT_WRITE_IN; - case NORTH -> slot = SLOT_WRITE_IN; - case SOUTH -> slot = SLOT_WRITE_IN; - case WEST -> slot = SLOT_WRITE_IN; - case EAST -> slot = SLOT_WRITE_IN; + 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, direction) -> { + int slot = -1; + switch (direction) { + case DOWN -> slot = SLOT_WRITE_OUT; + case UP -> slot = SLOT_WRITE_IN; + case NORTH -> slot = SLOT_WRITE_IN; + case SOUTH -> slot = SLOT_WRITE_IN; + case WEST -> slot = SLOT_WRITE_IN; + case EAST -> slot = SLOT_WRITE_IN; + } + return new ItemHandlerSlotMasked(blockEntity.getInventory(), slot); } - return new ItemHandlerSlotMasked(blockEntity.getInventory(), slot); - } - ); - event.registerBlockEntity( - Capabilities.NetworkElementProvider.BLOCK, - blockEntityType, - (blockEntity, direction) -> blockEntity.getNetworkElementProvider() - ); + ); + add( + Capabilities.NetworkElementProvider.BLOCK, + (blockEntity, direction) -> blockEntity.getNetworkElementProvider() + ); + } } @Override diff --git a/src/main/java/org/cyclops/integratedrest/blockentity/BlockEntityHttpConfig.java b/src/main/java/org/cyclops/integratedrest/blockentity/BlockEntityHttpConfig.java index f378961..297ba52 100644 --- a/src/main/java/org/cyclops/integratedrest/blockentity/BlockEntityHttpConfig.java +++ b/src/main/java/org/cyclops/integratedrest/blockentity/BlockEntityHttpConfig.java @@ -2,7 +2,6 @@ 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.integratedrest.IntegratedRest; import org.cyclops.integratedrest.RegistryEntries; @@ -21,11 +20,7 @@ public BlockEntityHttpConfig() { (eConfig) -> new BlockEntityType<>(BlockEntityHttp::new, Sets.newHashSet(RegistryEntries.BLOCK_HTTP.get()), null) ); - IntegratedRest._instance.getModEventBus().addListener(this::registerCapability); - } - - protected void registerCapability(RegisterCapabilitiesEvent event) { - BlockEntityHttp.registerHttpCapabilities(event, getInstance()); + IntegratedRest._instance.getModEventBus().addListener(new BlockEntityHttp.CapabilityRegistrar(this::getInstance)::register); } }