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 a5a1436 commit 9da84e1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 33 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -43,6 +42,7 @@

import javax.annotation.Nullable;
import java.util.Optional;
import java.util.function.Supplier;

/**
* A tile entity for the http block.
Expand All @@ -65,30 +65,35 @@ public BlockEntityHttp(BlockPos blockPos, BlockState blockState) {
this.variable = new HttpVariableAdapter(this, ValueTypes.CATEGORY_ANY, ValueTypeBoolean.ValueBoolean.of(false));
}

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

}

0 comments on commit 9da84e1

Please sign in to comment.