Skip to content

Commit

Permalink
Use BlockEntityCapabilityRegistrar
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Jun 21, 2024
1 parent f5d9194 commit 1403ee1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ 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
integrateddynamics_version=1.21.2-748
release_type=release
fingerprint=bd0353b3e8a2810d60dd584e256e364bc3bedd44

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -47,19 +47,24 @@ public BlockEntityScriptingDrive(BlockPos blockPos, BlockState blockState) {
getInventory().addDirtyMarkListener(this);
}

public static void registerScriptingDriveCapabilities(RegisterCapabilitiesEvent event, BlockEntityType<? extends BlockEntityScriptingDrive> 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<BlockEntityScriptingDrive> {
public CapabilityRegistrar(Supplier<BlockEntityType<? extends BlockEntityScriptingDrive>> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}

}

0 comments on commit 1403ee1

Please sign in to comment.