Search in sources :

Example 1 with BlockAlloyWire

use of com.bluepowermod.block.machine.BlockAlloyWire in project BluePower by Qmunity.

the class TileWire method getCapability.

@Nonnull
@Override
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) {
    List<Direction> directions = new ArrayList<>(BlockBPCableBase.FACING.getPossibleValues());
    if (level != null) {
        BlockState state = getBlockState();
        if (state.getBlock() instanceof BlockAlloyWire) {
            // Remove upward connections
            directions.remove(state.getValue(BlockAlloyWire.FACING));
            // Make sure the cable is on the same side of the block
            directions.removeIf(d -> level.getBlockState(worldPosition.relative(d)).getBlock() instanceof BlockAlloyWire && level.getBlockState(worldPosition.relative(d)).getValue(BlockAlloyWire.FACING) != state.getValue(BlockAlloyWire.FACING));
        // Make sure the cable is the same color or none
        // if(device.getInsulationColor(null) != MinecraftColor.NONE)
        // directions.removeIf(d -> {
        // TileEntity tile = world.getBlockEntity(worldPosition.relative(d));
        // return tile instanceof TileWire
        // && !(((TileWire) tile).device.getInsulationColor(d) == device.getInsulationColor(d.getOpposite())
        // || ((TileWire) tile).device.getInsulationColor(d) == MinecraftColor.NONE);
        // });
        }
    }
    if (cap == CapabilityRedstoneDevice.UNINSULATED_CAPABILITY && (side == null || directions.contains(side))) {
        if (redstoneCap == null)
            redstoneCap = LazyOptional.of(() -> device);
        return redstoneCap.cast();
    }
    return LazyOptional.empty();
}
Also used : BlockState(net.minecraft.block.BlockState) ArrayList(java.util.ArrayList) BlockAlloyWire(com.bluepowermod.block.machine.BlockAlloyWire) Direction(net.minecraft.util.Direction) Nonnull(javax.annotation.Nonnull)

Aggregations

BlockAlloyWire (com.bluepowermod.block.machine.BlockAlloyWire)1 ArrayList (java.util.ArrayList)1 Nonnull (javax.annotation.Nonnull)1 BlockState (net.minecraft.block.BlockState)1 Direction (net.minecraft.util.Direction)1